module 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. class Campaigns include HTTParty base_uri('https://api.expresspigeon.com/campaigns') debug_output($stderr) # Campaigns creation # # POST https://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. 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 https://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) 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 https://api.expresspigeon.com/campaigns/{campaign_id} def report(campaign_id) self.class.get("/#{campaign_id}") end # Get opened events for campaign # # GET https://api.expresspigeon.com/campaigns/{campaign_id}/opened def report_opened(campaign_id) self.class.get("/#{campaign_id}/opened") end # Get clicked events for campaign # # GET https://api.expresspigeon.com/campaigns/{campaign_id}/clicked def report_clicked(campaign_id) self.class.get("/#{campaign_id}/clicked") end # Get bounced contacts for campaign # # GET https://api.expresspigeon.com/campaigns/{campaign_id}/bounced def report_bounced(campaign_id) self.class.get("/#{campaign_id}/bounced") end # Get unsubscribed contacts for campaign # # GET https://api.expresspigeon.com/campaigns/{campaign_id}/unsubscribed def report_unsubscribed(campaign_id) self.class.get("/#{campaign_id}/unsubscribed") end # Get spam contacts for campaign # # GET https://api.expresspigeon.com/campaigns/{campaign_id}/spam def report_spam(campaign_id) self.class.get("/#{campaign_id}/spam") end end end