-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrecipients.go
93 lines (74 loc) · 2.29 KB
/
recipients.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
92
93
package mailersend
import (
"context"
"fmt"
"net/http"
)
const recipientBasePath = "/recipients"
type RecipientService service
// recipientRoot - recipients response
type recipientRoot struct {
Data []recipient `json:"data"`
Links Links `json:"links"`
Meta Meta `json:"meta"`
}
// singleRecipientRoot - single recipient response
type singleRecipientRoot struct {
Data recipientData `json:"data"`
}
type recipientData struct {
ID string `json:"id"`
Email string `json:"email"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
DeletedAt string `json:"deleted_at"`
Emails []interface{} `json:"emails"`
Domain Domain `json:"domain"`
}
// recipient - a single recipient
type recipient struct {
ID string `json:"id"`
Email string `json:"email"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
DeletedAt string `json:"deleted_at"`
}
// ListRecipientOptions - modifies the behavior of RecipientService.List method
type ListRecipientOptions struct {
DomainID string `url:"domain_id,omitempty"`
Page int `url:"page,omitempty"`
Limit int `url:"limit,omitempty"`
}
func (s *RecipientService) List(ctx context.Context, options *ListRecipientOptions) (*recipientRoot, *Response, error) {
req, err := s.client.newRequest(http.MethodGet, recipientBasePath, options)
if err != nil {
return nil, nil, err
}
root := new(recipientRoot)
res, err := s.client.do(ctx, req, root)
if err != nil {
return nil, res, err
}
return root, res, nil
}
func (s *RecipientService) Get(ctx context.Context, recipientID string) (*singleRecipientRoot, *Response, error) {
path := fmt.Sprintf("%s/%s", recipientBasePath, recipientID)
req, err := s.client.newRequest(http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
root := new(singleRecipientRoot)
res, err := s.client.do(ctx, req, root)
if err != nil {
return nil, res, err
}
return root, res, nil
}
func (s *RecipientService) Delete(ctx context.Context, recipientID string) (*Response, error) {
path := fmt.Sprintf("%s/%s", recipientBasePath, recipientID)
req, err := s.client.newRequest(http.MethodDelete, path, nil)
if err != nil {
return nil, err
}
return s.client.do(ctx, req, nil)
}