Class: Promoter::Campaign

Inherits:
Object
  • Object
show all
Defined in:
lib/promoter/campaign.rb

Constant Summary collapse

API_URL =
"https://app.promoter.io/api/campaigns"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_countObject (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_durationObject (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_countObject (readonly)

Returns the value of attribute eligible_count.



7
8
9
# File 'lib/promoter/campaign.rb', line 7

def eligible_count
  @eligible_count
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/promoter/campaign.rb', line 7

def id
  @id
end

#last_surveyed_dateObject (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_dateObject (readonly)

Returns the value of attribute launch_date.



7
8
9
# File 'lib/promoter/campaign.rb', line 7

def launch_date
  @launch_date
end

#nameObject (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(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::Campaign.all(page: 2)"
    query_string = "page=#{options}"
  else
    # default to first page
    options[:page] ||= 1
    query_string = URI.encode_www_form(options)
  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