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, contact) ⇒ Object
JSON document represents a contact to be created or updated.
Methods included from API
#auth_key, auto_responders, campaigns, contacts, #del, #get, #get_auth_key, #http, lists, messages, #post, #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.
32 33 34 35 36 37 |
# File 'lib/expresspigeon-ruby/contacts.rb', line 32 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, contact) ⇒ Object
JSON document represents a contact 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: representation of a contact
25 26 27 |
# File 'lib/expresspigeon-ruby/contacts.rb', line 25 def upsert(list_id, contact) post @endpoint, params = {:list_id => list_id, :contacts => [contact]} end |