Class: ConstantContact::Services::ContactService
- Inherits:
-
BaseService
- Object
- BaseService
- ConstantContact::Services::ContactService
- Defined in:
- lib/constantcontact/services/contact_service.rb
Instance Attribute Summary
Attributes inherited from BaseService
Instance Method Summary collapse
-
#add_contact(contact, params = {}) ⇒ Contact
Add a new contact to the Constant Contact account.
-
#delete_contact(contact_id) ⇒ Boolean
Delete contact details for a specific contact.
-
#delete_contact_from_list(contact_id, list_id) ⇒ Boolean
Delete a contact from a specific contact list.
-
#delete_contact_from_lists(contact_id) ⇒ Boolean
Delete a contact from all contact lists.
-
#get_contact(contact_id) ⇒ Contact
Get contact details for a specific contact.
-
#get_contacts(params = {}) ⇒ ResultSet<Contact>
Get an array of contacts.
-
#update_contact(contact, params = {}) ⇒ Contact
Update contact details for a specific contact.
Methods inherited from BaseService
Constructor Details
This class inherits a constructor from ConstantContact::Services::BaseService
Instance Method Details
#add_contact(contact, params = {}) ⇒ Contact
Add a new contact to the Constant Contact account
46 47 48 49 50 51 52 |
# File 'lib/constantcontact/services/contact_service.rb', line 46 def add_contact(contact, params = {}) url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.contacts') url = build_url(url, params) payload = contact.to_json response = RestClient.post(url, payload, get_headers()) Components::Contact.create(JSON.parse(response.body)) end |
#delete_contact(contact_id) ⇒ Boolean
Delete contact details for a specific contact
58 59 60 61 62 63 |
# File 'lib/constantcontact/services/contact_service.rb', line 58 def delete_contact(contact_id) url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.contact'), contact_id) url = build_url(url) response = RestClient.delete(url, get_headers()) response.code == 204 end |
#delete_contact_from_list(contact_id, list_id) ⇒ Boolean
Delete a contact from a specific contact list
81 82 83 84 85 86 |
# File 'lib/constantcontact/services/contact_service.rb', line 81 def delete_contact_from_list(contact_id, list_id) url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.contact_list'), contact_id, list_id) url = build_url(url) response = RestClient.delete(url, get_headers()) response.code == 204 end |
#delete_contact_from_lists(contact_id) ⇒ Boolean
Delete a contact from all contact lists
69 70 71 72 73 74 |
# File 'lib/constantcontact/services/contact_service.rb', line 69 def delete_contact_from_lists(contact_id) url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.contact_lists'), contact_id) url = build_url(url) response = RestClient.delete(url, get_headers()) response.code == 204 end |
#get_contact(contact_id) ⇒ Contact
Get contact details for a specific contact
33 34 35 36 37 38 39 |
# File 'lib/constantcontact/services/contact_service.rb', line 33 def get_contact(contact_id) url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.contact'), contact_id) url = build_url(url) response = RestClient.get(url, get_headers()) Components::Contact.create(JSON.parse(response.body)) end |
#get_contacts(params = {}) ⇒ ResultSet<Contact>
Get an array of contacts
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/constantcontact/services/contact_service.rb', line 14 def get_contacts(params = {}) url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.contacts') url = build_url(url, params) response = RestClient.get(url, get_headers()) body = JSON.parse(response.body) contacts = [] body['results'].each do |contact| contacts << Components::Contact.create(contact) end Components::ResultSet.new(contacts, body['meta']) end |
#update_contact(contact, params = {}) ⇒ Contact
Update contact details for a specific contact
93 94 95 96 97 98 99 |
# File 'lib/constantcontact/services/contact_service.rb', line 93 def update_contact(contact, params = {}) url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.contact'), contact.id) url = build_url(url, params) payload = contact.to_json response = RestClient.put(url, payload, get_headers()) Components::Contact.create(JSON.parse(response.body)) end |