Class: ExpressPigeon::Contacts

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/express_pigeon/contacts.rb

Overview

Contacts

Contacts end point allows you to create, read, update and delete contacts on your lists. A contact consists of required email and various standard and custom fields.

Instance Method Summary collapse

Constructor Details

#initialize(auth_key) ⇒ Contacts

Returns a new instance of Contacts.



13
14
15
# File 'lib/express_pigeon/contacts.rb', line 13

def initialize(auth_key)
  self.class.headers('X-auth-key' => auth_key)
end

Instance Method Details

#create(list_id, contacts) ⇒ Object Also known as: update

Create or update contacts

POST api.expresspigeon.com/contacts



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/express_pigeon/contacts.rb', line 27

def create(list_id, contacts)
  fail "Contacts must be an Array received #{contacts.class.name}." unless contacts.is_a?(Array)

  options = {
    'list_id' => list_id,
    'contacts' => contacts
  }

  self.class.post(
    '/',
    body: options.to_json,
    headers: {
      'Content-Type' => 'application/json'
    }
  )
end

#delete(_email_address) ⇒ Object

Delete a single contact

DELETE api.expresspigeon.com/contacts



48
49
# File 'lib/express_pigeon/contacts.rb', line 48

def delete()
end

#find(email_address) ⇒ Object

Read a single contact by email

GET api.expresspigeon.com/contacts



20
21
22
# File 'lib/express_pigeon/contacts.rb', line 20

def find(email_address)
  self.class.get('/', query: { email: email_address })
end

#move(source_list_id, target_list_id, email_addresses) ⇒ Object

Move contacts between lists

POST api.expresspigeon.com/contacts/move



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/express_pigeon/contacts.rb', line 54

def move(source_list_id, target_list_id, email_addresses)
  fail "Email address must be an Array received #{email_addresses.class.name}." unless email_addresses.is_a?(Array)

  options = {}
  options['source_list'] = source_list_id
  options['target_list'] = target_list_id
  options['contacts'] =  email_addresses

  self.class.post(
    '/move',
    body: options.to_json,
    headers: {
      'Content-Type' => 'application/json'
    }
  )
end