Class: VerticalResponse::API::List

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

Instance Attribute Summary

Attributes inherited from Client

#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, build_params, build_query_params, config, default_query_params, embed_resource, resource_uri

Constructor Details

#initialize(*args) ⇒ List

Returns a new instance of List.



21
22
23
24
25
# File 'lib/list.rb', line 21

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

.base_uri(*args) ⇒ Object

Base URI for the List resource



16
17
18
# File 'lib/list.rb', line 16

def base_uri(*args)
  @base_uri ||= File.join(super.to_s, 'lists')
end

Instance Method Details

#contacts(options = {}) ⇒ Object

Returns all the contacts that belong to the list



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

def contacts(options = {})
  @contact_class.all(options)
end

#create_contact(params) ⇒ Object

Creates a contact for the list with the parameters provided



42
43
44
# File 'lib/list.rb', line 42

def create_contact(params)
  @contact_class.create(params)
end

#create_contacts(params) ⇒ Object

Creates contacts in batch for the list with the parameters provided



47
48
49
50
# File 'lib/list.rb', line 47

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

#delete_contact(contact) ⇒ Object

Deletes a contact from the list



53
54
55
56
57
58
# File 'lib/list.rb', line 53

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 list



61
62
63
64
65
66
# File 'lib/list.rb', line 61

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



37
38
39
# File 'lib/list.rb', line 37

def find_contact(contact_id, options = {})
  @contact_class.find(contact_id, options)
end

#messages(options = {}) ⇒ Object

Returns all the messages targetted to the current list



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

def messages(options = {})
  @message_class.all(options)
end