class ConstantContact::Services::ContactService

Public Class Methods

add_contact(contact, params = {}) click to toggle source

Add a new contact to the Constant Contact account @param [Contact] contact - Contact to add @param [Boolean] params - query params to be appended to the request @return [Contact]

# File lib/constantcontact/services/contact_service.rb, line 47
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) click to toggle source

Delete contact details for a specific contact @param [Integer] contact_id - Unique contact id @return [Boolean]

# File lib/constantcontact/services/contact_service.rb, line 59
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) click to toggle source

Delete a contact from a specific contact list @param [Integer] contact_id - Contact id to be removed @param [Integer] list_id - ContactList id to remove the contact from @return [Boolean]

# File lib/constantcontact/services/contact_service.rb, line 82
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) click to toggle source

Delete a contact from all contact lists @param [Integer] contact_id - Contact id to be removed from lists @return [Boolean]

# File lib/constantcontact/services/contact_service.rb, line 70
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) click to toggle source

Get contact details for a specific contact @param [Integer] contact_id - Unique contact id @return [Contact]

# File lib/constantcontact/services/contact_service.rb, line 34
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 = {}) click to toggle source

Get an array of contacts @param [Hash] params - query parameters to be appended to the request @return [ResultSet<Contact>]

# File lib/constantcontact/services/contact_service.rb, line 15
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 = {}) click to toggle source

Update contact details for a specific contact @param [Contact] contact - Contact to be updated @param [Hash] params - query params to be appended to the request @return [Contact]

# File lib/constantcontact/services/contact_service.rb, line 94
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