-
Notifications
You must be signed in to change notification settings - Fork 0
/
servers.go
94 lines (82 loc) · 3.27 KB
/
servers.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
package postmark
import (
"fmt"
"net/http"
)
// Server represents a Postmark server.
type Server struct {
ID int `json:"ID,omitempty"`
Name string `json:"Name,omitempty"`
APITokens []string `json:"ApiTokens,omitempty"`
Color string `json:"Color,omitempty"`
SMTPAPIActivated bool `json:"SmtpApiActivated"`
RawEmailEnabled bool `json:"RawEmailEnabled"`
ServerLink string `json:"ServerLink,omitempty"`
InboundAddress string `json:"InboundAddress,omitempty"`
InboundHookURL string `json:"InboundHookUrl,omitempty"`
BounceHookURL string `json:"BounceHookUrl,omitempty"`
OpenHookURL string `json:"OpenHookUrl,omitempty"`
DeliveryHookURL string `json:"DeliveryHookUrl,omitempty"`
PostFirstOpenOnly bool `json:"PostFirstOpenOnly"`
InboundDomain string `json:"InboundDomain,omitempty"`
InboundHash string `json:"InboundHash,omitempty"`
InboundSpamThreshold int `json:"InboundSpamThreshold,omitempty"`
TrackOpens bool `json:"TrackOpens"`
TrackLinks string `json:"TrackLinks,omitempty"`
IncludeBounceContentInHook bool `json:"IncludeBounceContentInHook"`
ClickHookURL string `json:"ClickHookUrl,omitempty"`
EnableSMTPAPIErrorHooks bool `json:"EnableSmtpApiErrorHooks"`
}
// GetServer uses the `/servers/<id>` endpoint. It requires a valid account
// token, not server token.
func (c *Client) GetServer(serverID string) (*Server, error) {
var ret Server
req := parameters{
method: http.MethodGet,
endpoint: fmt.Sprintf("/servers/%s", serverID),
expectedStatusCode: http.StatusOK,
respTarget: &ret,
token: c.AccountToken,
}
err := c.doRequest(req)
return &ret, err
}
// CreateServer creates a server based on the passed struct and returns a
// server struct with the ID populated.
func (c *Client) CreateServer(newsrvr Server) (*Server, error) {
var ret Server
req := parameters{
method: http.MethodPost,
endpoint: "/servers",
expectedStatusCode: http.StatusOK,
respTarget: &ret,
token: c.AccountToken,
payload: newsrvr,
}
err := c.doRequest(req)
return &ret, err
}
// UpdateServer updates a server based on the passed struct. Boolean values
// will always be sent and *must* be set.
func (c *Client) UpdateServer(serverID string, upsrvr Server) error {
req := parameters{
method: http.MethodPut,
endpoint: fmt.Sprintf("/servers/%s", serverID),
expectedStatusCode: http.StatusOK,
token: c.AccountToken,
payload: upsrvr,
}
return c.doRequest(req)
}
// DeleteServer will delete a server based on the serverID. Note that server
// deletion via API requires special access that requires a support ticket to
// Postmark.
func (c *Client) DeleteServer(serverID string) error {
req := parameters{
method: http.MethodDelete,
endpoint: fmt.Sprintf("/servers/%s", serverID),
expectedStatusCode: http.StatusOK,
token: c.AccountToken,
}
return c.doRequest(req)
}