Class: MailchimpAPI::Member

Inherits:
Base
  • Object
show all
Extended by:
Support::Countable
Includes:
Support::PatchUpdate
Defined in:
lib/mailchimp_api/resources/member.rb

Instance Method Summary collapse

Methods included from Support::Countable

count

Methods inherited from Base

activate_session, exists?, headers, reset_session, #to_h

Instance Method Details

#notes(params = {}) ⇒ Object

The path to get notes is ‘/3.0/lists/:list_id/members/:member_id’ Unfortunately, ActiveResource does not support nested resources, only single parent resources:

github.com/rails/activeresource/blob/4accda8bc03ceae0ad626f8cec0b4751e89a58ad/lib/active_resource/associations.rb#L151

Using a has_many, there is no way to include the ‘list_id`, so we just create our own notes method.



19
20
21
# File 'lib/mailchimp_api/resources/member.rb', line 19

def notes(params = {})
  @notes ||= MailchimpAPI::Note.find(:all, params: { member_id: id }.deep_merge(prefix_options).deep_merge(params))
end

#permanent_deleteObject

Delete all personally identifiable information related to a list member, and remove them from a list. This will make it impossible to re-import the list member



36
37
38
39
40
41
42
# File 'lib/mailchimp_api/resources/member.rb', line 36

def permanent_delete
  run_callbacks :destroy do
    path = element_path(prefix_options) + '/actions/delete-permanent'

    connection.post path, nil, self.class.headers
  end
end

#tags(params = {}) ⇒ Object

The path to get tags is ‘/3.0/lists/:list_id/members/:member_id’ Unfortunately, ActiveResource does not support nested resources, only single parent resources:

github.com/rails/activeresource/blob/4accda8bc03ceae0ad626f8cec0b4751e89a58ad/lib/active_resource/associations.rb#L151

Using a has_many, there is no way to include the ‘list_id`, so we just create our own tags method.



29
30
31
# File 'lib/mailchimp_api/resources/member.rb', line 29

def tags(params = {})
  @tags ||= MailchimpAPI::Tag.find(:all, params: { member_id: id }.deep_merge(prefix_options).deep_merge(params))
end

#update_tags(tags) ⇒ Object

Tags should be provided as an array of the form [‘tag1’, status: ‘active’, ‘tag2’, status: ‘inactive’]



45
46
47
48
49
50
# File 'lib/mailchimp_api/resources/member.rb', line 45

def update_tags(tags)
  path = element_path(prefix_options) + '/tags'
  body = { tags: tags }.to_json

  connection.post path, body, self.class.headers
end