Class: ConstantContact::Services::ListService
- Inherits:
-
BaseService
- Object
- BaseService
- ConstantContact::Services::ListService
- Defined in:
- lib/constantcontact/services/list_service.rb
Instance Attribute Summary
Attributes inherited from BaseService
Instance Method Summary collapse
-
#add_list(list) ⇒ ContactList
Add a new list to the Constant Contact account.
-
#get_contacts_from_list(list_id, params = nil) ⇒ Array<Contact>
Get all contacts from an individual list.
-
#get_list(list_id) ⇒ ContactList
Get an individual contact list.
-
#get_lists(params = {}) ⇒ Array<ContactList>
Get lists within an account.
-
#update_list(list) ⇒ ContactList
Update a Contact List.
Methods inherited from BaseService
Constructor Details
This class inherits a constructor from ConstantContact::Services::BaseService
Instance Method Details
#add_list(list) ⇒ ContactList
Add a new list to the Constant Contact account
29 30 31 32 33 34 35 |
# File 'lib/constantcontact/services/list_service.rb', line 29 def add_list(list) url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.lists') url = build_url(url) payload = list.to_json response = RestClient.post(url, payload, get_headers()) Components::ContactList.create(JSON.parse(response.body)) end |
#get_contacts_from_list(list_id, params = nil) ⇒ Array<Contact>
Get all contacts from an individual list
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/constantcontact/services/list_service.rb', line 65 def get_contacts_from_list(list_id, params = nil) url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.list_contacts'), list_id) url = build_url(url, params) response = RestClient.get(url, get_headers()) contacts = [] body = JSON.parse(response.body) body['results'].each do |contact| contacts << Components::Contact.create(contact) end Components::ResultSet.new(contacts, body['meta']) end |
#get_list(list_id) ⇒ ContactList
Get an individual contact list
53 54 55 56 57 58 |
# File 'lib/constantcontact/services/list_service.rb', line 53 def get_list(list_id) url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.list'), list_id) url = build_url(url) response = RestClient.get(url, get_headers()) Components::ContactList.create(JSON.parse(response.body)) end |
#get_lists(params = {}) ⇒ Array<ContactList>
Get lists within an account
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/constantcontact/services/list_service.rb', line 14 def get_lists(params = {}) url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.lists') url = build_url(url, params) response = RestClient.get(url, get_headers()) lists = [] JSON.parse(response.body).each do |contact| lists << Components::ContactList.create(contact) end lists end |
#update_list(list) ⇒ ContactList
Update a Contact List
41 42 43 44 45 46 47 |
# File 'lib/constantcontact/services/list_service.rb', line 41 def update_list(list) url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.list'), list.id) url = build_url(url) payload = list.to_json response = RestClient.put(url, payload, get_headers()) Components::ContactList.create(JSON.parse(response.body)) end |