git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/postmark/servers.go (about)

     1  package postmark
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"net/http"
     7  )
     8  
     9  type Server struct {
    10  	// ID of server
    11  	ID int64 `json:",omitempty"`
    12  	// Name of server
    13  	Name string
    14  	// ApiTokens associated with server.
    15  	ApiTokens []string `json:",omitempty"`
    16  	// ServerLink to your server overview page in Postmark.
    17  	ServerLink string `json:",omitempty"`
    18  	// Color of the server in the rack screen. Purple Blue Turquoise Green Red Yellow Grey
    19  	Color string
    20  	// SmtpApiActivated specifies whether or not SMTP is enabled on this server.
    21  	SmtpApiActivated bool
    22  	// RawEmailEnabled allows raw email to be sent with inbound.
    23  	RawEmailEnabled bool
    24  	// InboundAddress is the inbound email address
    25  	InboundAddress string `json:",omitempty"`
    26  	// InboundHookUrl to POST to every time an inbound event occurs.
    27  	InboundHookUrl string
    28  	// PostFirstOpenOnly - If set to true, only the first open by a particular recipient will initiate the open webhook. Any
    29  	// subsequent opens of the same email by the same recipient will not initiate the webhook.
    30  	PostFirstOpenOnly bool
    31  	// TrackOpens indicates if all emails being sent through this server have open tracking enabled.
    32  	TrackOpens bool
    33  	// InboundDomain is the inbound domain for MX setup
    34  	InboundDomain string
    35  	// InboundHash is the inbound hash of your inbound email address.
    36  	InboundHash string
    37  	// InboundSpamThreshold is the maximum spam score for an inbound message before it's blocked.
    38  	InboundSpamThreshold int64
    39  }
    40  
    41  func (client *Client) GetServer(ctx context.Context, serverID string) (Server, error) {
    42  	res := Server{}
    43  	err := client.request(ctx, requestParams{
    44  		Method: http.MethodGet,
    45  		URL:    fmt.Sprintf("/servers/%s", serverID),
    46  	}, &res)
    47  
    48  	return res, err
    49  }
    50  
    51  func (client *Client) EditServer(ctx context.Context, serverID string, server Server) (Server, error) {
    52  	res := Server{}
    53  	err := client.request(ctx, requestParams{
    54  		Method:  http.MethodPut,
    55  		URL:     fmt.Sprintf("/servers/%s", serverID),
    56  		Payload: server,
    57  	}, &res)
    58  
    59  	return res, err
    60  }
    61  
    62  func (client *Client) CreateServer(ctx context.Context, server Server) (Server, error) {
    63  	res := Server{}
    64  	err := client.request(ctx, requestParams{
    65  		Method:  http.MethodPost,
    66  		URL:     "/servers",
    67  		Payload: server,
    68  	}, &res)
    69  
    70  	return res, err
    71  }
    72  
    73  func (client *Client) DeleteServer(ctx context.Context, serverID string) (err error) {
    74  	err = client.request(ctx, requestParams{
    75  		Method: http.MethodDelete,
    76  		URL:    fmt.Sprintf("/servers/%s", serverID),
    77  	}, nil)
    78  
    79  	return
    80  }