forked from cloudflare/cloudflare-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
intelligence_whois.go
60 lines (50 loc) · 1.67 KB
/
intelligence_whois.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
package cloudflare
import (
"context"
"fmt"
"net/http"
"github.com/goccy/go-json"
)
// WHOIS represents whois information.
type WHOIS struct {
Domain string `json:"domain,omitempty"`
CreatedDate string `json:"created_date,omitempty"`
UpdatedDate string `json:"updated_date,omitempty"`
Registrant string `json:"registrant,omitempty"`
RegistrantOrg string `json:"registrant_org,omitempty"`
RegistrantCountry string `json:"registrant_country,omitempty"`
RegistrantEmail string `json:"registrant_email,omitempty"`
Registrar string `json:"registrar,omitempty"`
Nameservers []string `json:"nameservers,omitempty"`
}
// WHOISParameters represents parameters for a who is request.
type WHOISParameters struct {
AccountID string `url:"-"`
Domain string `url:"domain"`
}
// WHOISResponse represents an API response for a whois request.
type WHOISResponse struct {
Response
Result WHOIS `json:"result,omitempty"`
}
// IntelligenceWHOIS gets whois information for a domain.
//
// API Reference: https://api.cloudflare.com/#whois-record-get-whois-record
func (api *API) IntelligenceWHOIS(ctx context.Context, params WHOISParameters) (WHOIS, error) {
if params.AccountID == "" {
return WHOIS{}, ErrMissingAccountID
}
if params.Domain == "" {
return WHOIS{}, ErrMissingDomain
}
uri := buildURI(fmt.Sprintf("/accounts/%s/intel/whois", params.AccountID), params)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return WHOIS{}, err
}
var whoisResponse WHOISResponse
if err := json.Unmarshal(res, &whoisResponse); err != nil {
return WHOIS{}, err
}
return whoisResponse.Result, nil
}