-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathip_pool.go
More file actions
165 lines (128 loc) · 3.89 KB
/
ip_pool.go
File metadata and controls
165 lines (128 loc) · 3.89 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package sendgrid
import (
"context"
"fmt"
"net/url"
)
// IPPool represents an IP pool
type IPPool struct {
Name string `json:"name,omitempty"`
}
// see: https://www.twilio.com/docs/sendgrid/api-reference/ip-pools/retrieve-all-ip-pools
func (c *Client) GetIPPools(ctx context.Context) ([]*IPPool, error) {
path := "/ips/pools"
req, err := c.NewRequest("GET", path, nil)
if err != nil {
return nil, err
}
var pools []*IPPool
if err := c.Do(ctx, req, &pools); err != nil {
return nil, err
}
return pools, nil
}
type IP struct {
IP string `json:"ip,omitempty"`
Warmup bool `json:"warmup,omitempty"`
StartDate int64 `json:"start_date,omitempty"`
}
type OutputGetIPPool struct {
PoolName string `json:"pool_name,omitempty"`
IPs []*IP `json:"ips,omitempty"`
}
// see: https://www.twilio.com/docs/sendgrid/api-reference/ip-pools/retrieve-all-the-ips-in-a-specified-pool
func (c *Client) GetIPPool(ctx context.Context, name string) (*OutputGetIPPool, error) {
path := fmt.Sprintf("/ips/pools/%s", url.QueryEscape(name))
req, err := c.NewRequest("GET", path, nil)
if err != nil {
return nil, err
}
r := new(OutputGetIPPool)
if err := c.Do(ctx, req, r); err != nil {
return nil, err
}
return r, nil
}
type InputCreateIPPool struct {
Name string `json:"name,omitempty"`
}
type OutputCreateIPPool struct {
Name string `json:"name,omitempty"`
}
// see: https://www.twilio.com/docs/sendgrid/api-reference/ip-pools/create-an-ip-pool
func (c *Client) CreateIPPool(ctx context.Context, input *InputCreateIPPool) (*OutputCreateIPPool, error) {
req, err := c.NewRequest("POST", "/ips/pools", input)
if err != nil {
return nil, err
}
r := new(OutputCreateIPPool)
if err := c.Do(ctx, req, r); err != nil {
return nil, err
}
return r, nil
}
type InputUpdateIPPool struct {
Name string `json:"name,omitempty"`
}
type OutputUpdateIPPool struct {
Name string `json:"name,omitempty"`
}
// see: https://www.twilio.com/docs/sendgrid/api-reference/ip-pools/rename-an-ip-pool
func (c *Client) UpdateIPPool(ctx context.Context, name string, input *InputUpdateIPPool) (*OutputUpdateIPPool, error) {
path := fmt.Sprintf("/ips/pools/%s", url.QueryEscape(name))
req, err := c.NewRequest("PUT", path, input)
if err != nil {
return nil, err
}
r := new(OutputUpdateIPPool)
if err := c.Do(ctx, req, r); err != nil {
return nil, err
}
return r, nil
}
// see: https://www.twilio.com/docs/sendgrid/api-reference/ip-pools/delete-an-ip-pool
func (c *Client) DeleteIPPool(ctx context.Context, name string) error {
path := fmt.Sprintf("/ips/pools/%s", url.QueryEscape(name))
req, err := c.NewRequest("DELETE", path, nil)
if err != nil {
return err
}
if err := c.Do(ctx, req, nil); err != nil {
return err
}
return nil
}
type InputAddIPToPool struct {
IP string `json:"ip"`
}
type OutputAddIPToPool struct {
IP string `json:"ip,omitempty"`
Pools []string `json:"pools,omitempty"`
Warmup bool `json:"warmup,omitempty"`
StartDate int64 `json:"start_date,omitempty"`
}
// see: https://www.twilio.com/docs/sendgrid/api-reference/ip-pools/add-an-ip-address-to-a-pool
func (c *Client) AddIPToPool(ctx context.Context, poolName string, input *InputAddIPToPool) (*OutputAddIPToPool, error) {
path := fmt.Sprintf("/ips/pools/%s/ips", url.QueryEscape(poolName))
req, err := c.NewRequest("POST", path, input)
if err != nil {
return nil, err
}
r := new(OutputAddIPToPool)
if err := c.Do(ctx, req, r); err != nil {
return nil, err
}
return r, nil
}
// see: https://www.twilio.com/docs/sendgrid/api-reference/ip-pools/remove-an-ip-address-from-a-pool
func (c *Client) RemoveIPFromPool(ctx context.Context, poolName, ip string) error {
path := fmt.Sprintf("/ips/pools/%s/ips/%s", url.QueryEscape(poolName), url.QueryEscape(ip))
req, err := c.NewRequest("DELETE", path, nil)
if err != nil {
return err
}
if err := c.Do(ctx, req, nil); err != nil {
return err
}
return nil
}