Class: Promoter::ContactList

Inherits:
Object
  • Object
show all
Defined in:
lib/promoter/contact_list.rb

Constant Summary collapse

API_URL =
"https://app.promoter.io/api/lists"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ ContactList

Returns a new instance of ContactList.



9
10
11
12
# File 'lib/promoter/contact_list.rb', line 9

def initialize(attrs)
  @id = attrs['id']
  @name = attrs['name']
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/promoter/contact_list.rb', line 5

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/promoter/contact_list.rb', line 5

def name
  @name
end

Class Method Details

.all(page = 1) ⇒ Object



14
15
16
17
# File 'lib/promoter/contact_list.rb', line 14

def self.all(page=1)
  response = Request.get("#{API_URL}/?page=#{page}")
  response['results'].map {|attrs| new(attrs)}
end

.contact_ids_for(contact_list_id) ⇒ Object



19
20
21
22
# File 'lib/promoter/contact_list.rb', line 19

def self.contact_ids_for(contact_list_id)
  response = Request.get("#{API_URL}/#{contact_list_id}/contacts")
  response['results'].map {|attrs| attrs["id"]}
end

.create(attributes) ⇒ Object

Campaign Params Parameter Optional? Description name no The name of the campaign



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

def self.create(attributes)
  response = Request.post(API_URL + "/", attributes)
  new(response)
end

.remove_contact(params = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/promoter/contact_list.rb', line 24

def self.remove_contact(params={})
  contact_list_id = params[:contact_list_id]
  contact_id = params[:contact_id]
  contact_email = params[:email]

  if contact_list_id
    if contact_id
      Request.delete("#{API_URL}/#{contact_list_id}/contacts/#{contact_id}")
    elsif contact_email
      Request.post("#{API_URL}/#{contact_list_id}/remove/", {email: contact_email})
    else
      raise "Not enough information provided to remove a contact"
    end
  elsif contact_email
      Request.post("#{API_URL}/remove/", {email: contact_email})
  else
    raise "Not enough information provided to remove a contact"
  end
end