class ExpressPigeon::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.
Public Class Methods
# File lib/express_pigeon/campaigns.rb, line 12 def initialize(auth_key) self.class.headers('X-auth-key' => auth_key) end
Public Instance Methods
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.
# 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
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)
# 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 for a single campaign
GET api.expresspigeon.com/campaigns/{campaign_id}
# File lib/express_pigeon/campaigns.rb, line 85 def report(campaign_id) self.class.get("/#{campaign_id}") end
Get bounced contacts for campaign
GET api.expresspigeon.com/campaigns/{campaign_id}/bounced
# File lib/express_pigeon/campaigns.rb, line 106 def report_bounced(campaign_id) self.class.get("/#{campaign_id}/bounced") end
Get clicked events for campaign
GET api.expresspigeon.com/campaigns/{campaign_id}/clicked
# File lib/express_pigeon/campaigns.rb, line 99 def report_clicked(campaign_id) self.class.get("/#{campaign_id}/clicked") end
Get opened events for campaign
GET api.expresspigeon.com/campaigns/{campaign_id}/opened
# File lib/express_pigeon/campaigns.rb, line 92 def report_opened(campaign_id) self.class.get("/#{campaign_id}/opened") end
Get spam contacts for campaign
GET api.expresspigeon.com/campaigns/{campaign_id}/spam
# File lib/express_pigeon/campaigns.rb, line 120 def report_spam(campaign_id) self.class.get("/#{campaign_id}/spam") end
Get unsubscribed contacts for campaign
GET api.expresspigeon.com/campaigns/{campaign_id}/unsubscribed
# File lib/express_pigeon/campaigns.rb, line 113 def report_unsubscribed(campaign_id) self.class.get("/#{campaign_id}/unsubscribed") end