diff --git a/.gitignore b/.gitignore index 37a7e92..2dfdbe8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store *.out +.idea/ diff --git a/README.md b/README.md index 275ad80..c3b5553 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Stripped down package for sending emails through the Mandrill API. Inspired by [ ### Installation - go get -u github.com/keighl/mandrill + go get -u github.com/maytechnet/mandrill ### Upgrading to 1.0 @@ -22,7 +22,7 @@ res, apiError, err := client.MessagesSend(m) ### Documentation -http://godoc.org/github.com/keighl/mandrill +https://godoc.org/github.com/maytechnet/mandrill ### Regular Message diff --git a/mandrill.go b/mandrill.go index 6845bcb..53f90d8 100644 --- a/mandrill.go +++ b/mandrill.go @@ -136,6 +136,48 @@ type Message struct { SendAt string `json:"-"` } +// MessageInfo represents payload sent to the API +type MessageInfo struct { + // the message's unique id + Id string `json:"_id"` +} + +// ResponseMsgInfo holds details of the message info +type ResponseMsgInfo struct { + Ts int `json:"ts"` + ID string `json:"_id"` + Sender string `json:"sender"` + Template string `json:"template"` + Subject string `json:"subject"` + Email string `json:"email"` + Tags []string `json:"tags"` + Opens int `json:"opens"` + OpensDetail []struct { + Ts int `json:"ts"` + IP string `json:"ip"` + Location string `json:"location"` + Ua string `json:"ua"` + } `json:"opens_detail"` + Clicks int `json:"clicks"` + ClicksDetail []struct { + Ts int `json:"ts"` + URL string `json:"url"` + IP string `json:"ip"` + Location string `json:"location"` + Ua string `json:"ua"` + } `json:"clicks_detail"` + State string `json:"state"` + Metadata struct { + UserID string `json:"user_id"` + Website string `json:"website"` + } `json:"metadata"` + SMTPEvents []struct { + Ts int `json:"ts"` + Type string `json:"type"` + Diag string `json:"diag"` + } `json:"smtp_events"` +} + // To is a single recipient's information. type To struct { // the email address of the recipient @@ -209,13 +251,15 @@ func (err Error) Error() string { return err.Message } +const BaseURL = "https://mandrillapp.com/api/1.0/" + // ClientWithKey returns a mandrill.Client pointer armed with the supplied Mandrill API key // For integration testing, you can supply `SANDBOX_SUCCESS` or `SANDBOX_ERROR` as the API key. func ClientWithKey(key string) *Client { return &Client{ Key: key, HTTPClient: &http.Client{}, - BaseURL: "https://mandrillapp.com/api/1.0/", + BaseURL: BaseURL, } } @@ -258,6 +302,37 @@ func (c *Client) MessagesSend(message *Message) (responses []*Response, err erro return c.sendMessagePayload(data, "messages/send.json") } +// MessageInfo sends a message via an API client +func (c *Client) MessageInfo(info *MessageInfo) (responses *ResponseMsgInfo, err error) { + if c.Key == "SANDBOX_SUCCESS" { + return responses, nil + } + + if c.Key == "SANDBOX_ERROR" { + return nil, errors.New("SANDBOX_ERROR") + } + + if info.Id == "" { + return nil, errors.New("email ID empty") + } + + var data struct { + Key string `json:"key"` + Id string `json:"id"` + } + + data.Key = c.Key + data.Id = info.Id + + body, err := c.sendApiRequest(data, "messages/info.json") + if err != nil { + return responses, err + } + responses = new(ResponseMsgInfo) + err = json.Unmarshal(body, &responses) + return responses, err +} + // MessagesSendTemplate sends a message using a Mandrill template func (c *Client) MessagesSendTemplate(message *Message, templateName string, contents interface{}) (responses []*Response, err error) {