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 dfbc3c4
Showing 1 changed file with 46 additions and 2 deletions.
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 dfbc3c4

Please sign in to comment.