-
Notifications
You must be signed in to change notification settings - Fork 4
/
schedule_message.go
106 lines (86 loc) · 2.89 KB
/
schedule_message.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
94
95
96
97
98
99
100
101
102
103
104
105
106
package mailersend
import (
"context"
"fmt"
"net/http"
"time"
)
const messageScheduleBasePath = "/message-schedules"
type ScheduleMessageService service
type scheduleMessageRoot struct {
Data []scheduleMessageData `json:"data"`
Links Links `json:"links"`
Meta Meta `json:"meta"`
}
type scheduleMessageData struct {
MessageID string `json:"message_id"`
Subject string `json:"subject"`
SendAt time.Time `json:"send_at"`
Status string `json:"status"`
StatusMessage interface{} `json:"status_message"`
CreatedAt string `json:"created_at"`
}
type scheduleMessageSingleRoot struct {
Data scheduleMessageSingleData `json:"data"`
}
type ScheduleDomain struct {
ID string `json:"id"`
Name string `json:"name"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type ScheduleMessage struct {
ID string `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type scheduleMessageSingleData struct {
MessageID string `json:"message_id"`
Subject string `json:"subject"`
SendAt time.Time `json:"send_at"`
Status string `json:"status"`
StatusMessage interface{} `json:"status_message"`
CreatedAt time.Time `json:"created_at"`
Domain ScheduleDomain `json:"domain"`
Message ScheduleMessage `json:"message"`
}
// ListScheduleMessageOptions - modifies the behavior of MessageService.List Method
type ListScheduleMessageOptions struct {
DomainID string `url:"domain_id,omitempty"`
Status string `url:"status,omitempty"`
Page int `url:"page,omitempty"`
Limit int `url:"limit,omitempty"`
}
func (s *ScheduleMessageService) List(ctx context.Context, options *ListScheduleMessageOptions) (*scheduleMessageRoot, *Response, error) {
req, err := s.client.newRequest(http.MethodGet, messageScheduleBasePath, options)
if err != nil {
return nil, nil, err
}
root := new(scheduleMessageRoot)
res, err := s.client.do(ctx, req, root)
if err != nil {
return nil, res, err
}
return root, res, nil
}
func (s *ScheduleMessageService) Get(ctx context.Context, messageID string) (*scheduleMessageSingleRoot, *Response, error) {
path := fmt.Sprintf("%s/%s", messageScheduleBasePath, messageID)
req, err := s.client.newRequest(http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
root := new(scheduleMessageSingleRoot)
res, err := s.client.do(ctx, req, root)
if err != nil {
return nil, res, err
}
return root, res, nil
}
func (s *ScheduleMessageService) Delete(ctx context.Context, messageID string) (*Response, error) {
path := fmt.Sprintf("%s/%s", messageScheduleBasePath, messageID)
req, err := s.client.newRequest(http.MethodDelete, path, nil)
if err != nil {
return nil, err
}
return s.client.do(ctx, req, nil)
}