Class: VerticalResponse::API::List

Inherits:
Resource show all
Defined in:
lib/verticalresponse/api/list.rb

Instance Attribute Summary

Attributes inherited from Client

#access_token, #response

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

all, class_for_resource, class_name, create, #delete, exclude_methods, find, #id, id_attribute_name, id_regexp, object_collection, resource_id_from_url, resource_name, #stats, #update, #url, validate_supported_method!

Methods inherited from Client

add_default_query_param, assign_headers, base_service_uri, base_uri, base_uri_with_prefix, build_params, build_query_params, config, default_query_params, embed_resource, resource_uri, resource_uri_with_prefix, resource_uri_with_token

Constructor Details

#initialize(*args) ⇒ List



20
21
22
23
24
# File 'lib/verticalresponse/api/list.rb', line 20

def initialize(*args)
  super
  @contact_class = self.class.class_for_resource(Contact, id)
  @message_class = self.class.class_for_resource(Message, id)
end

Class Method Details

.resource_uri_suffixObject



15
16
17
# File 'lib/verticalresponse/api/list.rb', line 15

def resource_uri_suffix
  ['lists']
end

Instance Method Details

#contacts(options = {}) ⇒ Object

Returns all the contacts that belong to the list



33
34
35
36
# File 'lib/verticalresponse/api/list.rb', line 33

def contacts(options = {})
  @access_token ||= options[:access_token]
  @contact_class.all(options.merge(access_token: @access_token))
end

#create_contact(params) ⇒ Object

Creates a contact for the list with the parameters provided



49
50
51
52
# File 'lib/verticalresponse/api/list.rb', line 49

def create_contact(params)
  @access_token ||= params[:access_token]
  @contact_class.create(params.merge(access_token: @access_token))
end

#create_contacts(params) ⇒ Object

Creates contacts in batch for the list with the parameters provided



55
56
57
58
59
# File 'lib/verticalresponse/api/list.rb', line 55

def create_contacts(params)
  @access_token ||= params[:access_token]
  params = { :contacts => params } if params.is_a?(Array)
  @contact_class.create(params.merge(access_token: @access_token))
end

#delete_contact(contact) ⇒ Object

Deletes a contact from the list



62
63
64
65
66
67
# File 'lib/verticalresponse/api/list.rb', line 62

def delete_contact(contact)
  # Make a copy of the original contact but embedding the request
  # within the list resource
  contact_to_delete = @contact_class.new(contact.response)
  contact_to_delete.delete
end

#delete_contacts(contact_emails) ⇒ Object

Deletes contacts in batch from the lists



70
71
72
73
74
75
# File 'lib/verticalresponse/api/list.rb', line 70

def delete_contacts(contact_emails)
  Response.new @contact_class.delete(
    @contact_class.resource_uri,
    self.class.build_params({ :contacts => contact_emails })
  )
end

#find_contact(contact_id, options = {}) ⇒ Object



38
39
40
41
# File 'lib/verticalresponse/api/list.rb', line 38

def find_contact(contact_id, options = {})
  @access_token ||= options[:access_token]
  @contact_class.find(contact_id, options.merge(access_token: @access_token))
end

#find_contact_by_email(email, options = {}) ⇒ Object



43
44
45
46
# File 'lib/verticalresponse/api/list.rb', line 43

def find_contact_by_email(email, options = {})
  @access_token ||= options[:access_token]
  @contact_class.find_by_email(options.merge(access_token: @access_token, email_address: email))
end

#messages(options = {}) ⇒ Object

Returns all the messages targetted to the current list



27
28
29
30
# File 'lib/verticalresponse/api/list.rb', line 27

def messages(options = {})
  @access_token ||= options[:access_token]
  @message_class.all(options.merge(access_token: @access_token))
end