Class: ExpressPigeon::Contacts
- Inherits:
-
Object
- Object
- ExpressPigeon::Contacts
- Includes:
- API
- Defined in:
- lib/expresspigeon-ruby/contacts.rb
Instance Method Summary collapse
-
#delete(email, list_id = nil) ⇒ Object
Delete single contact.
- #find_by_email(email) ⇒ Object
-
#initialize ⇒ Contacts
constructor
A new instance of Contacts.
-
#upsert(list_id, contacts) ⇒ Object
JSON list represents contacts to be created or updated.
Methods included from API
#auth_key, autoresponders, campaigns, contacts, #del, #get, #get_auth_key, #http, lists, messages, #open_timeout=, #post, #read_timeout=, #root, templates
Constructor Details
#initialize ⇒ Contacts
Returns a new instance of Contacts.
5 6 7 |
# File 'lib/expresspigeon-ruby/contacts.rb', line 5 def initialize @endpoint = 'contacts' end |
Instance Method Details
#delete(email, list_id = nil) ⇒ Object
Delete single contact. If list_id is not provided, contact will be deleted from system. :param email: contact email to be deleted. :param list_id: list id to remove contact from, if not provided, contact will be deleted from system.
33 34 35 36 37 38 |
# File 'lib/expresspigeon-ruby/contacts.rb', line 33 def delete(email, list_id = nil) query = "email=#{CGI.escape(email)}" query += "&list_id=#{list_id}" if list_id del "#{@endpoint}?#{query}", nil end |
#find_by_email(email) ⇒ Object
9 10 11 |
# File 'lib/expresspigeon-ruby/contacts.rb', line 9 def find_by_email(email) get "#{@endpoint}?email=#{CGI.escape(email)}" end |
#upsert(list_id, contacts) ⇒ Object
JSON list represents contacts to be created or updated. The email field is required. When updating a contact, list_id is optional, since the contact is uniquely identified by email across all lists.
:param list_id: Contact list ID (Fixnum) the contact will be added to
:param contact: Hash describes new contact. The “email” field is required.
:returns: :status, :code, :messages, :contacts and :failed_contact_num if contact failed to create
26 27 28 |
# File 'lib/expresspigeon-ruby/contacts.rb', line 26 def upsert(list_id, contacts) post @endpoint, params = { list_id: list_id, contacts: [contacts].flatten } end |