-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient_domains.go
80 lines (68 loc) · 1.84 KB
/
client_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
package ovh
import (
"bytes"
"encoding/json"
"net/http"
"golang.org/x/net/context"
)
// Domains - OVH Domains API Client.
type Domains struct {
// Options - Client options.
*Options
}
// List - Lists domains.
func (domains *Domains) List(ctx context.Context) (result []string, err error) {
response, err := httpDo(ctx, domains.Options, "GET", apiURL("/domain"), nil)
if err != nil {
return
}
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
return nil, unexpectedStatusError(response)
}
err = json.NewDecoder(response.Body).Decode(&result)
if err != nil {
return
}
return
}
// Details - Gets domain details by domain name.
func (domains *Domains) Details(ctx context.Context, domain string) (result *Domain, err error) {
response, err := httpDo(ctx, domains.Options, "GET", apiURL("/domain/%s", domain), nil)
if err != nil {
return
}
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
return nil, unexpectedStatusError(response)
}
r := new(tempDomain)
err = json.NewDecoder(response.Body).Decode(&r)
if err != nil {
return
}
return r.getDomain(), nil
}
// Patch - Patches a domain details by domain name in domain.Name.
func (domains *Domains) Patch(ctx context.Context, domain string, p *DomainPatch) (err error) {
buffer := new(bytes.Buffer)
err = json.NewEncoder(buffer).Encode(&struct {
NameServerType string `json:"nameServerType,omitempty"`
TransferLockStatus string `json:"transferLockStatus,omitempty"`
}{
NameServerType: p.NameServerType,
TransferLockStatus: p.TransferLockStatus,
})
if err != nil {
return
}
response, err := httpDo(ctx, domains.Options, "PUT", apiURL("/domain/%s", domain), buffer)
if err != nil {
return
}
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
return unexpectedStatusError(response)
}
return
}