class Promoter::Contact
Constants
- API_URL
Attributes
Public Class Methods
Parameter Optional? Description page yes Returns which page of results to return. Defaults to 1
email yes Filter the results by email address. contact_list_id yes Filter the results by contact list
# File lib/promoter/contact.rb, line 27 def self.all(options={}) if !options.is_a?(Hash) puts "-- DEPRECATION WARNING--" puts "Passing in a number as a page is deprecated and will be removed from future versions of this gem.\nInstead pass in a hash of attributes.\n\n e.g. Promoter::Contact.all(page: 2)" query_string = "page=#{options}" else # default to first page options[:page] ||= 1 if options.key?(:contact_list_id) options[:contact_list__id] = options.delete(:contact_list_id) end query_string = URI.encode_www_form(options) end response = Request.get("#{API_URL}/?#{query_string}") response['results'].map { |attrs| new(attrs) } end
Contact
Params Parameter Optional? Description email no The email of the contact to add to the organization. first_name
yes The first name of the contact to add to the organization. last_name
yes The last name of the contact to add to the organization. contact_list yes A list of Contact
List Id’s to associate a contact to.
If one is not provided the contact will be associated to a default generated contact list.
attributes yes A dictionary of key value pairs of custom
attributes that will be associated with the contact and contact list.
send yes A boolean value set to true in order to express
intent to survey this contact for a given campaign.
campaign yes The campaign id you would like to associate the
contact to. Note: Campaign must have a contact list associated to it in order for the contact to be added correctly. Otherwise, the contact will be associated to a default generated contact list for your given organization.
# File lib/promoter/contact.rb, line 78 def self.create(params) # ensure the values of the 'attributes' param are strings if params[:attributes] params[:attributes] = values_to_string(params[:attributes]) end response = Request.post(API_URL + "/", params) new(response) end
# File lib/promoter/contact.rb, line 51 def self.destroy(email) attributes = { email: email } response = Request.post("#{API_URL}/remove/", attributes) new(response) end
# File lib/promoter/contact.rb, line 46 def self.find(id) response = Request.get("#{API_URL}/#{id}") new(response) end
# File lib/promoter/contact.rb, line 9 def initialize(attrs) @id = attrs["id"] @email = attrs["email"] @first_name = attrs["first_name"] @last_name = attrs["last_name"] @created_date = Time.parse(attrs["created_date"]) if attrs["created_date"] @attributes = attrs["attributes"] end
# File lib/promoter/contact.rb, line 88 def self.survey(params) contact_attributes = if Promoter.api_version == 2 api_url = "https://app.promoter.io/api/v2" contact_params = { attributes: params[:attributes] || {}, email: params[:email], first_name: params[:first_name], last_name: params[:last_name] } survey_params = { attributes: params[:survey_attributes] || {}, campaign_id: params[:campaign_id], contact: contact_params, } response = Request.post(api_url + "/survey/", survey_params) response["contact"] else Request.post(API_URL + "/survey/", params) end new(contact_attributes) end
used for ensuring the values of the attributes hashes are strings
# File lib/promoter/contact.rb, line 112 def self.values_to_string(hash) hash.each{ |key, value| hash[key] = value.to_s } end
Public Instance Methods
# File lib/promoter/contact.rb, line 18 def destroy Contact.destroy(self.email) end