Class: ExpressPigeon::Campaigns

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/express_pigeon/campaigns.rb

Overview

Campaigns

Campaign API provides the same service as sending email campaigns from the website. A campaign consists of newsletter template, subject, from name, reply to, and a lists of contacts a campaign can be sent to.

Instance Method Summary collapse

Constructor Details

#initialize(auth_key) ⇒ Campaigns

Returns a new instance of Campaigns.



12
13
14
# File 'lib/express_pigeon/campaigns.rb', line 12

def initialize(auth_key)
  self.class.headers('X-auth-key' => auth_key)
end

Instance Method Details

#create(list_id, template_id, name:, from_name:, reply_to:, subject:, google_analytics:, schedule_for: nil) ⇒ Object

Campaigns creation

POST api.expresspigeon.com/campaigns

list_id: The id of a list the campaign is sent to. The list must

be enabled.

template_id: The id of a newsletter template used for the campaign. name: The name of a campaign. This name is for your reference

only and will not be exposed to your audience. If you
have Google Analytics turned on, this value will also be
used for Google Analytics campaign.

from_name: This parameter is displayed as “From” field in the email

program when your recipients view your message. Use this
value to clearly state your name or name of your organization.

reply_to: This parameter specifies the email address which will

be getting replies from your recipients should they
choose to reply. The reply_to should be a valid email address.

subject: The subject of a newsletter google_analytics: Indicates whether Google Analytics should be enabled

for a campaign. Should be true or false.

schedule_for: Specifies what time a campaign should be sent. If it

is provided the campaign will be scheduled to this time,
otherwise campaign is sent immediately. The schedule_for
must be in ISO date format and should be in the future.


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/express_pigeon/campaigns.rb', line 40

def create(list_id, template_id, name:, from_name:, reply_to:, subject:, google_analytics:, schedule_for: nil)
  options = {}
  options['list_id'] = list_id
  options['template_id'] = template_id
  options['name'] = name
  options['from_name'] = from_name
  options['reply_to'] = reply_to
  options['subject'] = subject
  options['google_analytics'] = google_analytics
  options['schedule_for'] = schedule_for unless schedule_for.nil?

  self.class.post(
    '',
    body: options.to_json,
    headers: { 'Content-Type' => 'application/json' }
  )
end

#index(from_id: nil, from: nil, to: nil) ⇒ Object

List campaigns

GET api.expresspigeon.com/campaigns

Returns a list of at most 1000 created campaigns, to get the next batch use from_id parameter.

from_id: id from where to get the next batch,

e.g. the last id from the previous call

from: start of the sending period

(UTC, example: 2013-03-16T10:00:00.000+0000)

to: end of the sending period

(UTC, example: 2013-03-16T20:00:00.000+0000)


70
71
72
73
74
75
76
77
78
79
80
# File 'lib/express_pigeon/campaigns.rb', line 70

def index(from_id: nil, from: nil, to: nil)
  options = {}
  options['from_id'] = from_id unless from_id.nil?
  options['from'] = from unless from.nil?
  options['to'] = to unless to.nil?

  self.class.get(
    '',
    query: options
  )
end

#report(campaign_id) ⇒ Object

Report for a single campaign

GET api.expresspigeon.com/campaigns/campaign_id



85
86
87
# File 'lib/express_pigeon/campaigns.rb', line 85

def report(campaign_id)
  self.class.get("/#{campaign_id}")
end

#report_bounced(campaign_id) ⇒ Object

Get bounced contacts for campaign

GET api.expresspigeon.com/campaigns/campaign_id/bounced



106
107
108
# File 'lib/express_pigeon/campaigns.rb', line 106

def report_bounced(campaign_id)
  self.class.get("/#{campaign_id}/bounced")
end

#report_clicked(campaign_id) ⇒ Object

Get clicked events for campaign

GET api.expresspigeon.com/campaigns/campaign_id/clicked



99
100
101
# File 'lib/express_pigeon/campaigns.rb', line 99

def report_clicked(campaign_id)
  self.class.get("/#{campaign_id}/clicked")
end

#report_opened(campaign_id) ⇒ Object

Get opened events for campaign

GET api.expresspigeon.com/campaigns/campaign_id/opened



92
93
94
# File 'lib/express_pigeon/campaigns.rb', line 92

def report_opened(campaign_id)
  self.class.get("/#{campaign_id}/opened")
end

#report_spam(campaign_id) ⇒ Object

Get spam contacts for campaign

GET api.expresspigeon.com/campaigns/campaign_id/spam



120
121
122
# File 'lib/express_pigeon/campaigns.rb', line 120

def report_spam(campaign_id)
  self.class.get("/#{campaign_id}/spam")
end

#report_unsubscribed(campaign_id) ⇒ Object

Get unsubscribed contacts for campaign

GET api.expresspigeon.com/campaigns/campaign_id/unsubscribed



113
114
115
# File 'lib/express_pigeon/campaigns.rb', line 113

def report_unsubscribed(campaign_id)
  self.class.get("/#{campaign_id}/unsubscribed")
end