-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinbound_parse_webhook.go
More file actions
131 lines (105 loc) · 3.71 KB
/
inbound_parse_webhook.go
File metadata and controls
131 lines (105 loc) · 3.71 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
package sendgrid
import (
"context"
"fmt"
)
type OutputGetInboundParseWebhooks struct {
Result []*InboundParseWebhook `json:"result,omitempty"`
}
type InboundParseWebhook struct {
URL string `json:"url,omitempty"`
Hostname string `json:"hostname,omitempty"`
SpamCheck bool `json:"spam_check,omitempty"`
SendRaw bool `json:"send_raw,omitempty"`
}
// see: https://docs.sendgrid.com/api-reference/settings-inbound-parse/retrieve-all-parse-settings
func (c *Client) GetInboundParseWebhooks(ctx context.Context) ([]*InboundParseWebhook, error) {
req, err := c.NewRequest("GET", "/user/webhooks/parse/settings", nil)
if err != nil {
return nil, err
}
r := new(OutputGetInboundParseWebhooks)
if err := c.Do(ctx, req, &r); err != nil {
return nil, err
}
return r.Result, nil
}
type OutputGetInboundParseWebhook struct {
URL string `json:"url,omitempty"`
Hostname string `json:"hostname,omitempty"`
SpamCheck bool `json:"spam_check,omitempty"`
SendRaw bool `json:"send_raw,omitempty"`
}
// see: https://docs.sendgrid.com/api-reference/settings-inbound-parse/retrieve-a-specific-parse-setting
func (c *Client) GetInboundParseWebhook(ctx context.Context, hostname string) (*OutputGetInboundParseWebhook, error) {
path := fmt.Sprintf("/user/webhooks/parse/settings/%s", hostname)
req, err := c.NewRequest("GET", path, nil)
if err != nil {
return nil, err
}
r := new(OutputGetInboundParseWebhook)
if err := c.Do(ctx, req, &r); err != nil {
return nil, err
}
return r, nil
}
type InputCreateInboundParseWebhook struct {
URL string `json:"url,omitempty"`
Hostname string `json:"hostname,omitempty"`
SpamCheck bool `json:"spam_check"`
SendRaw bool `json:"send_raw"`
}
type OutputCreateInboundParseWebhook struct {
URL string `json:"url,omitempty"`
Hostname string `json:"hostname,omitempty"`
SpamCheck bool `json:"spam_check,omitempty"`
SendRaw bool `json:"send_raw,omitempty"`
}
// see: https://docs.sendgrid.com/api-reference/settings-inbound-parse/create-a-parse-setting
func (c *Client) CreateInboundParseWebhook(ctx context.Context, input *InputCreateInboundParseWebhook) (*OutputCreateInboundParseWebhook, error) {
req, err := c.NewRequest("POST", "/user/webhooks/parse/settings", input)
if err != nil {
return nil, err
}
r := new(OutputCreateInboundParseWebhook)
if err := c.Do(ctx, req, &r); err != nil {
return nil, err
}
return r, nil
}
type InputUpdateInboundParseWebhook struct {
URL string `json:"url,omitempty"`
SpamCheck bool `json:"spam_check"`
SendRaw bool `json:"send_raw"`
}
type OutputUpdateInboundParseWebhook struct {
URL string `json:"url,omitempty"`
Hostname string `json:"hostname,omitempty"`
SpamCheck bool `json:"spam_check,omitempty"`
SendRaw bool `json:"send_raw,omitempty"`
}
// see: https://docs.sendgrid.com/api-reference/settings-inbound-parse/update-a-parse-setting
func (c *Client) UpdateInboundParseWebhook(ctx context.Context, hostname string, input *InputUpdateInboundParseWebhook) (*OutputUpdateInboundParseWebhook, error) {
path := fmt.Sprintf("/user/webhooks/parse/settings/%s", hostname)
req, err := c.NewRequest("PATCH", path, input)
if err != nil {
return nil, err
}
r := new(OutputUpdateInboundParseWebhook)
if err := c.Do(ctx, req, &r); err != nil {
return nil, err
}
return r, nil
}
// see: https://docs.sendgrid.com/api-reference/settings-inbound-parse/delete-a-parse-setting
func (c *Client) DeleteInboundParseWebhook(ctx context.Context, hostname string) error {
path := fmt.Sprintf("/user/webhooks/parse/settings/%s", hostname)
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
}