class ExpressPigeon::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.
Public Class Methods
new(auth_key)
click to toggle source
# File lib/express_pigeon/contacts.rb, line 13 def initialize(auth_key) self.class.headers('X-auth-key' => auth_key) end
Public Instance Methods
create(list_id, contacts)
click to toggle source
Create or update contacts
POST api.expresspigeon.com/contacts
# 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
Also aliased as: update
delete(email_address, list_id: nil)
click to toggle source
Delete a single contact
DELETE api.expresspigeon.com/contacts
email: contact email to be deleted list_id: list id to remove contact from, if not provided contact will
be deleted from system.
# File lib/express_pigeon/contacts.rb, line 50 def delete(email_address, list_id: nil) options = {} options['email'] = email_address options['list_id'] = list_id unless list_id.nil? self.class.delete( '', body: options.to_json, headers: { 'Content-Type' => 'application/json' } ) end
find(email_address)
click to toggle source
Read a single contact by email
GET api.expresspigeon.com/contacts
# 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)
click to toggle source
Move contacts between lists
POST api.expresspigeon.com/contacts/move
# File lib/express_pigeon/contacts.rb, line 65 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