Class: Promoter::Campaign
- Inherits:
-
Object
- Object
- Promoter::Campaign
- Defined in:
- lib/promoter/campaign.rb
Constant Summary collapse
- API_URL =
"https://app.promoter.io/api/campaigns"
Instance Attribute Summary collapse
-
#contact_count ⇒ Object
readonly
Returns the value of attribute contact_count.
-
#drip_duration ⇒ Object
readonly
Returns the value of attribute drip_duration.
-
#eligible_count ⇒ Object
readonly
Returns the value of attribute eligible_count.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_surveyed_date ⇒ Object
readonly
Returns the value of attribute last_surveyed_date.
-
#launch_date ⇒ Object
readonly
Returns the value of attribute launch_date.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.all(options = {}) ⇒ Object
Parameter Optional? Description page yes Returns which page of results to return.
-
.create(attributes) ⇒ Object
Campaign Params Parameter Optional? Description name no The name of the campaign contact_list no The id of the contact list to associate to this campaign.
-
.send_surveys(campaign_id, all_contacts = false) ⇒ Object
Parameter Optional? Description all_contacts yes Can be set to true,false If set to true, the call will send surveys to all contacts in your specified contact list.
Instance Method Summary collapse
-
#initialize(attrs) ⇒ Campaign
constructor
A new instance of Campaign.
Constructor Details
#initialize(attrs) ⇒ Campaign
Returns a new instance of Campaign.
10 11 12 13 14 15 16 17 18 |
# File 'lib/promoter/campaign.rb', line 10 def initialize(attrs) @id = attrs["id"] @name = attrs["name"] @drip_duration = attrs["drip_duration"] @contact_count = attrs["all_count"] @eligible_count = attrs["eligible_count"] @last_surveyed_date = Time.parse(attrs["last_surveyed_date"]) if attrs["last_surveyed_date"] @launch_date = Time.parse(attrs["launch_date"]) if attrs["launch_date"] end |
Instance Attribute Details
#contact_count ⇒ Object (readonly)
Returns the value of attribute contact_count.
7 8 9 |
# File 'lib/promoter/campaign.rb', line 7 def contact_count @contact_count end |
#drip_duration ⇒ Object (readonly)
Returns the value of attribute drip_duration.
7 8 9 |
# File 'lib/promoter/campaign.rb', line 7 def drip_duration @drip_duration end |
#eligible_count ⇒ Object (readonly)
Returns the value of attribute eligible_count.
7 8 9 |
# File 'lib/promoter/campaign.rb', line 7 def eligible_count @eligible_count end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/promoter/campaign.rb', line 7 def id @id end |
#last_surveyed_date ⇒ Object (readonly)
Returns the value of attribute last_surveyed_date.
7 8 9 |
# File 'lib/promoter/campaign.rb', line 7 def last_surveyed_date @last_surveyed_date end |
#launch_date ⇒ Object (readonly)
Returns the value of attribute launch_date.
7 8 9 |
# File 'lib/promoter/campaign.rb', line 7 def launch_date @launch_date end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/promoter/campaign.rb', line 7 def name @name end |
Class Method Details
.all(options = {}) ⇒ Object
Parameter Optional? Description page yes Returns which page of results to return.
Defaults to 1
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/promoter/campaign.rb', line 23 def self.all(={}) if !.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::Campaign.all(page: 2)" query_string = "page=#{}" else # default to first page [:page] ||= 1 query_string = URI.encode_www_form() end response = Request.get("#{API_URL}/?#{query_string}") response['results'].map {|attrs| new(attrs)} end |
.create(attributes) ⇒ Object
Campaign Params Parameter Optional? Description name no The name of the campaign contact_list no The id of the contact list to associate to this campaign. The contact list will contain a list of contacts you will survey. email no The id of the email template you will use to survey your contacts in the contact list.
56 57 58 59 |
# File 'lib/promoter/campaign.rb', line 56 def self.create(attributes) response = Request.post(API_URL + "/", attributes) new(response) end |
.send_surveys(campaign_id, all_contacts = false) ⇒ Object
Parameter Optional? Description all_contacts yes Can be set to true,false
If set to true, the call will send surveys to all
contacts in your specified contact list.
If set to false, the call will send surveys to
contacts who have been added or updated since you
last sent surveys. The default behavior is when
all_contacts is set to false.
45 46 47 48 49 |
# File 'lib/promoter/campaign.rb', line 45 def self.send_surveys(campaign_id, all_contacts=false) response = Request.post("#{API_URL}/#{campaign_id}/send-surveys/", { all_contacts: all_contacts, response_format: :plain }) response.match /Success\, surveys sent\./ end |