-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinbound.go
168 lines (136 loc) · 4.41 KB
/
inbound.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
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
166
167
168
package mailersend
import (
"context"
"fmt"
"net/http"
)
const inboundBasePath = "/inbound"
type InboundService service
// inboundRoot - format of webhook response
type inboundRoot struct {
Data []inbound `json:"data"`
Links Links `json:"links"`
Meta Meta `json:"meta"`
}
// singleInboundRoot - format of inbound response
type singleInboundRoot struct {
Data inbound `json:"data"`
}
type inbound struct {
ID string `json:"id"`
Name string `json:"name"`
Address string `json:"address"`
Domain string `json:"domain"`
DNSCheckedAt interface{} `json:"dns_checked_at"`
Priority int `json:"priority"`
Enabled bool `json:"enabled"`
Filters []filters `json:"filters"`
Forwards []forwards `json:"forwards"`
MxValues mxValues `json:"mxValues"`
}
type filters struct {
Type string `json:"type"`
Key interface{} `json:"key"`
Comparer string `json:"comparer"`
Value string `json:"value"`
}
type forwards struct {
ID string `json:"id"`
Type string `json:"type"`
Value string `json:"value"`
Secret string `json:"secret"`
}
type mxValues struct {
Priority string `json:"priority"`
Target string `json:"target"`
}
// ListInboundOptions - modifies the behavior of *InboundService.List Method
type ListInboundOptions struct {
DomainID string `url:"domain_id"`
Page int `url:"page,omitempty"`
Limit int `url:"limit,omitempty"`
}
// CreateInboundOptions - the Options to set when creating an inbound resource
type CreateInboundOptions struct {
DomainID string `json:"domain_id"`
Name string `json:"name"`
DomainEnabled bool `json:"domain_enabled"`
InboundDomain string `json:"inbound_domain,omitempty"`
InboundAddress string `json:"inbound_address,omitempty"`
InboundSubdomain string `json:"inbound_subdomain,omitempty"`
InboundPriority int `json:"inbound_priority,omitempty"`
MatchFilter *MatchFilter `json:"match_filter,omitempty"`
CatchFilter *CatchFilter `json:"catch_filter,omitempty"`
Forwards []Forwards `json:"forwards"`
}
type MatchFilter struct {
Type string `json:"type,omitempty"`
}
type CatchFilter struct {
Type string `json:"type,omitempty"`
Filters []Filter `json:"filters,omitempty"`
}
type Forwards struct {
Type string `json:"type"`
Value string `json:"value"`
}
// UpdateInboundOptions - the Options to set when creating an inbound resource
type UpdateInboundOptions CreateInboundOptions
func (s *InboundService) List(ctx context.Context, options *ListInboundOptions) (*inboundRoot, *Response, error) {
req, err := s.client.newRequest(http.MethodGet, inboundBasePath, options)
if err != nil {
return nil, nil, err
}
root := new(inboundRoot)
res, err := s.client.do(ctx, req, root)
if err != nil {
return nil, res, err
}
return root, res, nil
}
func (s *InboundService) Get(ctx context.Context, inboundID string) (*singleInboundRoot, *Response, error) {
path := fmt.Sprintf("%s/%s", inboundBasePath, inboundID)
req, err := s.client.newRequest(http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
root := new(singleInboundRoot)
res, err := s.client.do(ctx, req, root)
if err != nil {
return nil, res, err
}
return root, res, nil
}
func (s *InboundService) Create(ctx context.Context, options *CreateInboundOptions) (*singleInboundRoot, *Response, error) {
req, err := s.client.newRequest(http.MethodPost, inboundBasePath, options)
if err != nil {
return nil, nil, err
}
root := new(singleInboundRoot)
res, err := s.client.do(ctx, req, root)
if err != nil {
return nil, res, err
}
return root, res, nil
}
func (s *InboundService) Update(ctx context.Context, inboundID string, options *UpdateInboundOptions) (*singleInboundRoot, *Response, error) {
path := fmt.Sprintf("%s/%s", inboundBasePath, inboundID)
req, err := s.client.newRequest(http.MethodPut, path, options)
if err != nil {
return nil, nil, err
}
root := new(singleInboundRoot)
res, err := s.client.do(ctx, req, root)
if err != nil {
return nil, res, err
}
return root, res, nil
}
func (s *InboundService) Delete(ctx context.Context, inboundID string) (*Response, error) {
path := fmt.Sprintf("%s/%s", inboundBasePath, inboundID)
req, err := s.client.newRequest(http.MethodDelete, path, nil)
if err != nil {
return nil, err
}
return s.client.do(ctx, req, nil)
}