Skip to content

Commit

Permalink
Merge pull request #7 from mattevans/add-metadata-email-struct
Browse files Browse the repository at this point in the history
feat(email): added Metadata to model
  • Loading branch information
mattevans authored Nov 1, 2022
2 parents 04f4aba + 72cbb80 commit 94af12d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
sudo: false
language: go
go:
- 1.17.x
- tip
- 1.19.x
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ emailReq := &postmark.Email{
},
Tag: "onboarding",
TrackOpens: true,
Metadata: map[string]string{
"client-id": "123456",
"client-ip": "127.0.0.1",
},
}

email, response, err := client.Email.Send(emailReq)
Expand All @@ -63,6 +67,10 @@ emailReq := &postmark.Email{
TextBody: "Hello dear Postmark user",
Tag: "onboarding",
TrackOpens: true,
Metadata: map[string]string{
"client-id": "123456",
"client-ip": "127.0.0.1",
},
}

email, response, err := client.Email.Send(emailReq)
Expand Down
1 change: 1 addition & 0 deletions email.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Email struct {
Attachments []EmailAttachment `json:",omitempty"`
TrackOpens bool `json:",omitempty"`
MessageStream string `json:",omitempty"`
Metadata map[string]string `json:",omitempty"`
}

// EmailHeader represents the values for an email header.
Expand Down
6 changes: 5 additions & 1 deletion examples/send-email/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"net/http"

postmark "github.com/mattevans/postmark-go"
"github.com/mattevans/postmark-go"
)

func main() {
Expand All @@ -23,6 +23,10 @@ func main() {
TextBody: "Hello dear Postmark user",
Tag: "onboarding",
TrackOpens: true,
Metadata: map[string]string{
"client-id": "123456",
"client-ip": "127.0.0.1",
},
}

// Send it!
Expand Down
5 changes: 2 additions & 3 deletions postmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
)

const (
packageVersion = "0.1.5"
packageVersion = "0.1.6"
backendURL = "https://api.postmarkapp.com"
userAgent = "postmark-go/" + packageVersion
)
Expand Down Expand Up @@ -152,7 +151,7 @@ func CheckResponse(r *http.Response) error {

errorResponse := &ErrorResponse{Response: r}

data, err := ioutil.ReadAll(r.Body)
data, err := io.ReadAll(r.Body)
if err == nil && len(data) > 0 {
err := json.Unmarshal(data, errorResponse)
if err != nil {
Expand Down

0 comments on commit 94af12d

Please sign in to comment.