-
Notifications
You must be signed in to change notification settings - Fork 3
/
account_infromation.go
61 lines (57 loc) · 1.72 KB
/
account_infromation.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
package hunter
import (
"bytes"
"context"
"encoding/json"
"net/http"
)
// AccountInformation is returned by the Account function.
type AccountInformation struct {
Data struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Email string `json:"email"`
PlanName string `json:"plan_name"`
PlanLevel int `json:"plan_level"`
ResetDate string `json:"reset_date"`
TeamID int `json:"team_id"`
Calls struct {
Used int `json:"used"`
Available int `json:"available"`
} `json:"calls"`
} `json:"data"`
}
// Account is a function to get information regarding your
// Hunter account at any time. This call is free.
//
// This context-based version of the function would be more suitable for long-running
// applications like servers.
func (c *Client) Account() (*AccountInformation, error) {
body, err := c.request(context.Background(), http.MethodGet, "https://api.hunter.io/v2/account", nil)
if err != nil {
return nil, err
}
result := new(AccountInformation)
err = json.NewDecoder(bytes.NewReader(body)).Decode(result)
if err != nil {
return nil, err
}
return result, nil
}
// AccountWithContext is a function to get information regarding your
// Hunter account at any time. This call is free.
//
// This context-based version of the function would be more suitable for long-running
// applications like servers.
func (c *Client) AccountWithContext(ctx context.Context) (*AccountInformation, error) {
body, err := c.request(ctx, http.MethodGet, "https://api.hunter.io/v2/account", nil)
if err != nil {
return nil, err
}
result := new(AccountInformation)
err = json.NewDecoder(bytes.NewReader(body)).Decode(result)
if err != nil {
return nil, err
}
return result, nil
}