forked from mrz1836/postmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservers.go
113 lines (104 loc) · 3.79 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package postmark
import (
"context"
"encoding/json"
"fmt"
"net/http"
)
// Server represents a server registered in your Postmark account
type Server struct {
// ID of server
ID int64
// Name of server
Name string
// APITokens associated with server.
APITokens []string `json:"ApiTokens"`
// ServerLink to your server overview page in Postmark.
ServerLink string
// Color of the server in the rack screen. Purple Blue Turquoise Green Red Yellow Grey
Color string
// SMTPAPIActivated specifies whether SMTP is enabled on this server.
SMTPAPIActivated bool `json:"SmtpApiActivated"`
// RawEmailEnabled allows raw email to be sent with inbound.
RawEmailEnabled bool
// DeliveryType specifies the type of environment for your server: Live or Sandbox, defaults to Live
DeliveryType string `json:"DeliveryType"`
// InboundAddress is the inbound email address
InboundAddress string
// InboundHookURL to POST to every time an inbound event occurs.
InboundHookURL string `json:"InboundHookUrl"`
// BounceHookURL to POST to every time a bounce event occurs.
BounceHookURL string `json:"BounceHookUrl"`
// OpenHookURL to POST to every time an open event occurs.
OpenHookURL string `json:"OpenHookUrl"`
// PostFirstOpenOnly - If set to true, only the first open by a particular recipient will initiate the open webhook. Any
// subsequent opens of the same email by the same recipient will not initiate the webhook.
PostFirstOpenOnly bool
// TrackOpens indicates if all emails being sent through this server have open tracking enabled.
TrackOpens bool
// TrackLinks specifies link tracking in emails: None, HtmlAndText, HtmlOnly, TextOnly
TrackLinks string `json:"TrackLinks"`
// IncludeBounceContentInHook determines if bounce content is included in webhook.
IncludeBounceContentInHook bool `json:"IncludeBounceContentInHook"`
// InboundDomain is the inbound domain for MX setup
InboundDomain string
// InboundHash is the inbound hash of your inbound email address.
InboundHash string
// InboundSpamThreshold is the maximum spam score for an inbound message before it's blocked.
InboundSpamThreshold int64
// EnableSmtpApiErrorHooks specifies whether SMTP API Errors will be included with bounce webhooks.
EnableSmtpApiErrorHooks bool `json:"EnableSmtpApiErrorHooks"`
}
func (s Server) MarshalJSON() ([]byte, error) {
type Aux Server
// If TrackLinks is empty, set it to "None"
trackLinks := s.TrackLinks
if trackLinks == "" {
trackLinks = "None"
}
// If DeliveryType is empty, set it to default value "Live"
deliveryType := s.DeliveryType
if deliveryType == "" {
deliveryType = "Live"
}
return json.Marshal(&struct {
Aux
TrackLinks string `json:"TrackLinks"`
DeliveryType string `json:"DeliveryType"`
}{
Aux: Aux(s),
TrackLinks: trackLinks,
DeliveryType: deliveryType,
})
}
// GetServer fetches a specific server via serverID
func (client *Client) GetServer(ctx context.Context, serverID string) (Server, error) {
res := Server{}
err := client.doRequest(ctx, parameters{
Method: http.MethodGet,
Path: fmt.Sprintf("servers/%s", serverID),
TokenType: accountToken,
}, &res)
return res, err
}
// EditServer updates details for a specific server with serverID
func (client *Client) EditServer(ctx context.Context, serverID string, server Server) (Server, error) {
// res := Server{}
err := client.doRequest(ctx, parameters{
Method: http.MethodPut,
Path: fmt.Sprintf("servers/%s", serverID),
TokenType: accountToken,
}, &server)
return server, err
}
// CreateServer creates a server
func (client *Client) CreateServer(ctx context.Context, server Server) (Server, error) {
res := Server{}
err := client.doRequest(ctx, parameters{
Method: http.MethodPost,
Path: "servers",
TokenType: accountToken,
Payload: server,
}, &res)
return res, err
}