-
Notifications
You must be signed in to change notification settings - Fork 14
/
emails_senders_service.go
96 lines (75 loc) · 2.04 KB
/
emails_senders_service.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
package sendpulse_sdk_go
import (
"context"
"fmt"
"net/http"
)
type SendersService struct {
client *Client
}
func newSendersService(cl *Client) *SendersService {
return &SendersService{client: cl}
}
func (service *SendersService) CreateSender(ctx context.Context, name string, email string) error {
path := "/senders"
type paramsFormat struct {
Name string `json:"name"`
Email string `json:"email"`
}
params := paramsFormat{
Name: name,
Email: email,
}
var response struct {
Result bool `json:"result"`
}
_, err := service.client.newRequest(ctx, http.MethodPost, path, params, &response, true)
return err
}
func (service *SendersService) GetSenderActivationCode(ctx context.Context, email string) error {
path := fmt.Sprintf("/senders/%s/code", email)
var response struct {
Result bool `json:"result"`
}
_, err := service.client.newRequest(ctx, http.MethodGet, path, nil, &response, true)
return err
}
func (service *SendersService) ActivateSender(ctx context.Context, email, code string) error {
path := fmt.Sprintf("/senders/%s/code", email)
type paramsFormat struct {
Code string `json:"code"`
}
params := paramsFormat{
Code: code,
}
var response struct {
Result bool `json:"result"`
}
_, err := service.client.newRequest(ctx, http.MethodPost, path, params, &response, true)
return err
}
type Sender struct {
Name string `json:"name"`
Email string `json:"email"`
Status string `json:"status"`
}
func (service *SendersService) GetSenders(ctx context.Context) ([]*Sender, error) {
path := "/senders"
var respData []*Sender
_, err := service.client.newRequest(ctx, http.MethodGet, path, nil, &respData, true)
return respData, err
}
func (service *SendersService) DeleteSender(ctx context.Context, email string) error {
path := "/senders"
type paramsFormat struct {
Email string `json:"email"`
}
params := paramsFormat{
Email: email,
}
var response struct {
Result bool `json:"result"`
}
_, err := service.client.newRequest(ctx, http.MethodDelete, path, params, &response, true)
return err
}