-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathemail_counter.go
71 lines (67 loc) · 2.06 KB
/
email_counter.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
package hunter
import (
"bytes"
"context"
"encoding/json"
"net/http"
)
// EmailCounterResult is returned by the CountEmails function.
type EmailCounterResult struct {
Data struct {
Total int `json:"total"`
PersonalEmails int `json:"personal_emails"`
GenericEmails int `json:"generic_emails"`
Department struct {
Executive int `json:"executive"`
It int `json:"it"`
Finance int `json:"finance"`
Management int `json:"management"`
Sales int `json:"sales"`
Legal int `json:"legal"`
Support int `json:"support"`
Hr int `json:"hr"`
Marketing int `json:"marketing"`
Communication int `json:"communication"`
} `json:"department"`
Seniority struct {
Junior int `json:"junior"`
Senior int `json:"senior"`
Executive int `json:"executive"`
} `json:"seniority"`
} `json:"data"`
Meta struct {
Params struct {
Domain string `json:"domain"`
Type interface{} `json:"type"`
} `json:"params"`
} `json:"meta"`
}
// CountEmails allows you to verify the deliverability of an email address.
func (c *Client) CountEmails(params Params) (*EmailCounterResult, error) {
body, err := c.request(context.Background(), http.MethodGet, "https://api.hunter.io/v2/email-count", params)
if err != nil {
return nil, err
}
result := new(EmailCounterResult)
err = json.NewDecoder(bytes.NewReader(body)).Decode(result)
if err != nil {
return nil, err
}
return result, nil
}
// CountEmailsWithContext allows you to verify the deliverability of an email address.
//
// This context-based version of the function would be more suitable for long-running
// applications like servers.
func (c *Client) CountEmailsWithContext(ctx context.Context, params Params) (*EmailCounterResult, error) {
body, err := c.request(ctx, http.MethodGet, "https://api.hunter.io/v2/email-count", params)
if err != nil {
return nil, err
}
result := new(EmailCounterResult)
err = json.NewDecoder(bytes.NewReader(body)).Decode(result)
if err != nil {
return nil, err
}
return result, nil
}