-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbulk_email.go
66 lines (54 loc) · 1.77 KB
/
bulk_email.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
package mailersend
import (
"context"
"fmt"
"net/http"
"time"
)
const bulkEmailBasePath = "/bulk-email"
type BulkEmailService service
type bulkEmailResponse struct {
Message string `json:"message"`
BulkEmailID string `json:"bulk_email_id"`
}
type bulkEmailRoot struct {
Data bulkEmailData `json:"data"`
}
type bulkEmailData struct {
ID string `json:"id"`
State string `json:"state"`
TotalRecipientsCount int `json:"total_recipients_count"`
SuppressedRecipientsCount int `json:"suppressed_recipients_count"`
SuppressedRecipients interface{} `json:"suppressed_recipients"`
ValidationErrorsCount int `json:"validation_errors_count"`
ValidationErrors interface{} `json:"validation_errors"`
MessagesID []string `json:"messages_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// Send - send bulk messages
func (s *BulkEmailService) Send(ctx context.Context, message []*Message) (*bulkEmailResponse, *Response, error) {
req, err := s.client.newRequest(http.MethodPost, bulkEmailBasePath, message)
if err != nil {
return nil, nil, err
}
root := new(bulkEmailResponse)
res, err := s.client.do(ctx, req, root)
if err != nil {
return nil, res, err
}
return root, res, nil
}
func (s *BulkEmailService) Status(ctx context.Context, bulkEmailID string) (*bulkEmailRoot, *Response, error) {
path := fmt.Sprintf("%s/%s", bulkEmailBasePath, bulkEmailID)
req, err := s.client.newRequest(http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
root := new(bulkEmailRoot)
res, err := s.client.do(ctx, req, root)
if err != nil {
return nil, res, err
}
return root, res, nil
}