Class: ExpressPigeon::Contacts
- Inherits:
-
Object
- Object
- ExpressPigeon::Contacts
- 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
-
#create(list_id, contacts) ⇒ Object
(also: #update)
Create or update contacts.
-
#delete(_email_address) ⇒ Object
Delete a single contact.
-
#find(email_address) ⇒ Object
Read a single contact by email.
-
#initialize(auth_key) ⇒ Contacts
constructor
A new instance of Contacts.
-
#move(source_list_id, target_list_id, email_addresses) ⇒ Object
Move contacts between lists.
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
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) = { 'list_id' => list_id, 'contacts' => contacts } self.class.post( '/', body: .to_json, headers: { 'Content-Type' => 'application/json' } ) end |
#delete(_email_address) ⇒ Object
Delete a single contact
48 49 |
# File 'lib/express_pigeon/contacts.rb', line 48 def delete(_email_address) end |
#find(email_address) ⇒ Object
Read a single contact by email
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
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) = {} ['source_list'] = source_list_id ['target_list'] = target_list_id ['contacts'] = email_addresses self.class.post( '/move', body: .to_json, headers: { 'Content-Type' => 'application/json' } ) end |