Skip to content

Commit

Permalink
Added Member Tags API calls
Browse files Browse the repository at this point in the history
I added two API calls.
 - GET: /lists/{list_id}/members/{subscriber_hash}/tags
 - POST: /lists/{list_id}/members/{subscriber_hash}/tags

API doc: https://mailchimp.com/developer/reference/lists/list-members/list-member-tags/
  • Loading branch information
ko30005 committed Aug 8, 2020
1 parent ac0caad commit 362748f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
48 changes: 46 additions & 2 deletions members.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const (

member_notes_path = single_member_path + "/notes"
single_member_note_path = member_notes_path + "/%s"

member_tags_path = single_member_path + "/tags"
)

type ListOfMembers struct {
Expand Down Expand Up @@ -116,8 +118,9 @@ type MemberNoteShort struct {
}

type MemberTag struct {
ID int `json:"id"`
Name string `json:"name"`
ID int `json:"id"`
Name string `json:"name"`
DateAdded string `json:"date_added"`
}

func (list ListResponse) GetMembers(params *InterestCategoriesQueryParams) (*ListOfMembers, error) {
Expand Down Expand Up @@ -344,3 +347,44 @@ func (mem Member) DeleteNote(id string) (bool, error) {
endpoint := fmt.Sprintf(single_member_note_path, mem.ListID, mem.ID, id)
return mem.api.RequestOk("DELETE", endpoint)
}

// ------------------------------------------------------------------------------------------------
// Tags
// ------------------------------------------------------------------------------------------------

type ListOfMemberTags struct {
baseList

Tags []MemberTag `json:"tags"`
}

type ListOfTagsRequest struct {
Tags []TagsRequest `json:"tags"`
IsSyncing bool `json:"is_syncing"`
}

type TagsRequest struct {
Name string `json:"name"`
Status string `json:"status"`
}

func (mem Member) GetTags(params *BasicQueryParams) (*ListOfMemberTags, error) {
if err := mem.CanMakeRequest(); err != nil {
return nil, err
}

endpoint := fmt.Sprintf(member_tags_path, mem.ListID, mem.ID)
response := new(ListOfMemberTags)

return response, mem.api.Request("GET", endpoint, params, nil, response)
}

func (mem Member) CreateTags(body *ListOfTagsRequest) error {
if err := mem.CanMakeRequest(); err != nil {
return err
}

endpoint := fmt.Sprintf(member_tags_path, mem.ListID, mem.ID)

return mem.api.Request("POST", endpoint, nil, body, nil)
}

0 comments on commit 362748f

Please sign in to comment.