Skip to content

Commit

Permalink
Added Member Tags API calls
Browse files Browse the repository at this point in the history
Implement
 - 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 Jul 12, 2020
1 parent 34f0aa1 commit 2440890
Showing 1 changed file with 47 additions and 3 deletions.
50 changes: 47 additions & 3 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 All @@ -35,7 +37,7 @@ type MemberRequest struct {
Location *MemberLocation `json:"location,omitempty"`
IPOpt string `json:"ip_opt,omitempty"`
IPSignup string `json:"ip_signup,omitempty"`
Tags []string `json:"tags,omitempty"`
Tags []string `json:"tags,omitempty"`
TimestampSignup string `json:"timestamp_signup,omitempty"`
TimestampOpt string `json:"timestamp_opt,omitempty"`
}
Expand Down Expand Up @@ -90,8 +92,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 @@ -318,3 +321,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 2440890

Please sign in to comment.