Skip to content

Commit

Permalink
Get/Edit current server (/server endpoint)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Truscott committed Jul 13, 2018
2 parents 548f0c6 + 2eb53be commit a377bdf
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
29 changes: 29 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package postmark

// GetCurrentServer gets details for the server associated
// with the currently in-use server API Key
func (client *Client) GetCurrentServer() (Server, error) {
res := Server{}
err := client.doRequest(parameters{
Method: "GET",
Path: "server",
TokenType: server_token,
}, &res)

return res, err
}

///////////////////////////////////////
///////////////////////////////////////

// EditCurrentServer updates details for the server associated
// with the currently in-use server API Key
func (client *Client) EditCurrentServer(server Server) (Server, error) {
res := Server{}
err := client.doRequest(parameters{
Method: "PUT",
Path: "server",
TokenType: server_token,
}, &res)
return res, err
}
90 changes: 90 additions & 0 deletions server_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package postmark

import (
"testing"
"net/http"

"goji.io/pat"
)

func TestGetCurrentServer(t *testing.T) {
responseJSON := `{
"ID": 1,
"Name": "Staging Testing",
"ApiTokens": [
"server token"
],
"ServerLink": "https://postmarkapp.com/servers/1/overview",
"Color": "red",
"SmtpApiActivated": true,
"RawEmailEnabled": false,
"DeliveryHookUrl": "http://hooks.example.com/delivery",
"InboundAddress": "[email protected]",
"InboundHookUrl": "http://hooks.example.com/inbound",
"BounceHookUrl": "http://hooks.example.com/bounce",
"IncludeBounceContentInHook": true,
"OpenHookUrl": "http://hooks.example.com/open",
"PostFirstOpenOnly": false,
"TrackOpens": false,
"TrackLinks" : "None",
"ClickHookUrl" : "http://hooks.example.com/click",
"InboundDomain": "",
"InboundHash": "yourhash",
"InboundSpamThreshold": 0
}`

tMux.HandleFunc(pat.Get("/server"), func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(responseJSON))
})

res, err := client.GetCurrentServer()
if err != nil {
t.Fatalf("GetCurrentServer: %s", err.Error())
}

if res.Name != "Staging Testing" {
t.Fatalf("GetCurrentServer: wrong name!: %s", res.Name)
}
}

func TestEditCurrentServer(t *testing.T) {
responseJSON := `{
"ID": 1,
"Name": "Production Testing",
"ApiTokens": [
"Server Token"
],
"ServerLink": "https://postmarkapp.com/servers/1/overview",
"Color": "blue",
"SmtpApiActivated": false,
"RawEmailEnabled": false,
"DeliveryHookUrl": "http://hooks.example.com/delivery",
"InboundAddress": "[email protected]",
"InboundHookUrl": "http://hooks.example.com/inbound",
"BounceHookUrl": "http://hooks.example.com/bounce",
"IncludeBounceContentInHook": true,
"OpenHookUrl": "http://hooks.example.com/open",
"PostFirstOpenOnly": false,
"TrackOpens": false,
"TrackLinks": "None",
"ClickHookUrl": "http://hooks.example.com/click",
"InboundDomain": "",
"InboundHash": "yourhash",
"InboundSpamThreshold": 10
}`
tMux.HandleFunc(pat.Put("/server"), func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(responseJSON))
})

res, err := client.EditCurrentServer(Server{
Name: "Production Testing",
})

if err != nil {
t.Fatalf("EditCurrentServer: %s", err.Error())
}

if res.Name != "Production Testing" {
t.Fatalf("EditCurrentServer: wrong name!: %s", res.Name)
}
}

0 comments on commit a377bdf

Please sign in to comment.