forked from Sighery/gonjalla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomains.go
91 lines (74 loc) · 2.05 KB
/
domains.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package gonjalla
import (
"encoding/json"
"time"
)
// Domain struct contains data returned by `list-domains` and `get-domains`
type Domain struct {
Name string `json:"name"`
Status string `json:"status"`
Expiry time.Time `json:"expiry"`
Locked *bool `json:"locked,omitempty"`
Mailforwarding *bool `json:"mailforwarding,omitempty"`
MaxNameservers *int `json:"max_nameservers,omitempty"`
}
// Domain availability and price data returned by `find-domains`
type MarketDomain struct {
Name string `json:"name"`
Status string `json:"status"`
Price int `json:"price"`
}
// ListDomains returns a listing of domains with minimal data
func ListDomains(token string) ([]Domain, error) {
params := map[string]interface{}{}
data, err := Request(token, "list-domains", params)
if err != nil {
return nil, err
}
type Response struct {
Domains []Domain `json:"domains"`
}
var response Response
err = json.Unmarshal(data, &response)
if err != nil {
return nil, err
}
return response.Domains, nil
}
// GetDomain returns detailed information for each domain
func GetDomain(token string, domain string) (Domain, error) {
params := map[string]interface{}{
"domain": domain,
}
data, err := Request(token, "get-domain", params)
if err != nil {
return Domain{}, err
}
var domainStruct Domain
err = json.Unmarshal(data, &domainStruct)
if err != nil {
return Domain{}, err
}
return domainStruct, nil
}
// FindDomains returns availability and price information for a query.
// If query was `example`, then it'd show availability and price of
// domains `example.com`, `example.net`, etc.
func FindDomains(token string, query string) ([]MarketDomain, error) {
params := map[string]interface{}{
"query": query,
}
data, err := Request(token, "find-domains", params)
if err != nil {
return nil, err
}
type Response struct {
Domains []MarketDomain `json:"domains"`
}
var response Response
err = json.Unmarshal(data, &response)
if err != nil {
return nil, err
}
return response.Domains, nil
}