Class: ConstantContact::Services::ListService
- Inherits:
-
BaseService
- Object
- BaseService
- ConstantContact::Services::ListService
- Defined in:
- lib/constantcontact/services/list_service.rb
Class 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.
Class Method Details
.add_list(list) ⇒ ContactList
Add a new list to the Constant Contact account
30 31 32 33 34 35 36 |
# File 'lib/constantcontact/services/list_service.rb', line 30 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
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/constantcontact/services/list_service.rb', line 66 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
54 55 56 57 58 59 |
# File 'lib/constantcontact/services/list_service.rb', line 54 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
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/constantcontact/services/list_service.rb', line 15 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
42 43 44 45 46 47 48 |
# File 'lib/constantcontact/services/list_service.rb', line 42 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 |