-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get/Edit current server (/server endpoint)
- Loading branch information
Showing
2 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |