Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Clever Coding Standards Agreement

- [ ] Author and Review Statement, "We agree this code adheres to our [Clever Global Coding Standards](https://app.getguru.com/folders/ibabX5oT/Engineering-Standards-Best-Practices?activeCard=a8a444f4-9149-4ec7-a0fd-8ba42519d93e) and other applicable [Coding Standards](https://app.getguru.com/folders/ibabX5oT/Engineering-Standards-Best-Practices)"

## JIRA
[Link to JIRA](insert url here)

## Overview
(insert PR description here)

## Testing
(how did you test this)

## Rollout
(are there any special rollout considerations? specific steps? risks?)

## Rollback
(specific steps? risks?)
11 changes: 11 additions & 0 deletions catalog-info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: mandrill
description: Simple package for sending emails through the Mandrill API.
owner: unknown
spec:
type: unknown
lifecycle: production
owner: unknown
system: Clever
16 changes: 13 additions & 3 deletions mandrill.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
)
Expand Down Expand Up @@ -81,9 +82,9 @@ type Message struct {
// whether or not this message is important, and should be delivered ahead of non-important messages
Important bool `json:"important,omitempty"`
// whether or not to turn on open tracking for the message
TrackOpens bool `json:"track_opens,omitempty"`
TrackOpens *bool `json:"track_opens,omitempty"`
// whether or not to turn on click tracking for the message
TrackClicks bool `json:"track_clicks,omitempty"`
TrackClicks *bool `json:"track_clicks,omitempty"`
// whether or not to automatically generate a text part for messages that are not given text
AutoText bool `json:"auto_text,omitempty"`
// whether or not to automatically generate an HTML part for messages that are not given HTML
Expand Down Expand Up @@ -305,6 +306,7 @@ func (c *Client) sendMessagePayload(data interface{}, path string) (responses []
}

func (c *Client) sendApiRequest(data interface{}, path string) (body []byte, err error) {
var emptyErr Error
payload, _ := json.Marshal(data)

resp, err := c.HTTPClient.Post(c.BaseURL+path, "application/json", bytes.NewReader(payload))
Expand All @@ -320,7 +322,15 @@ func (c *Client) sendApiRequest(data interface{}, path string) (body []byte, err

if resp.StatusCode >= 400 {
resError := &Error{}
err = json.Unmarshal(body, resError)
if err := json.Unmarshal(body, resError); err != nil {
return body, err
}

// if we don't receive a meaningful message from Mandrill, let's return the http status
if *resError == emptyErr {
return body, fmt.Errorf("received unexpected http response from mandrill API: %s", resp.Status)
}

return body, resError
}

Expand Down
10 changes: 10 additions & 0 deletions mandrill_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http/httptest"
"net/url"
"reflect"
"strings"
"testing"
)

Expand Down Expand Up @@ -82,6 +83,15 @@ func Test_MessagesSendTemplate_Fail(t *testing.T) {
expect(t, reflect.DeepEqual(correctResponse, err), true)
}

func Test_MessagesSendTemplate_Unexpected(t *testing.T) {
server, m := testTools(415, `{}`)
defer server.Close()
responses, err := m.MessagesSendTemplate(&Message{}, "cheese", map[string]string{"name": "bob"})

expect(t, len(responses), 0)
expect(t, strings.Contains(err.Error(), "415"), true)
}

// MessagesSend //////////

func Test_MessageSend_Success(t *testing.T) {
Expand Down