class ExpressPigeon::Messages
Sending Transactional emails requires that newsletter templates for these emails are created prior to sending. Such template can have merge fields, in a format ${field_name}. This feature allows a high degree of flexibility for message customization.
The newsletter to be sent can have a number of merge fields, with data for merging dynamically provided during a call.
Constants
- REPORTING_PERIODS
Public Class Methods
# File lib/express_pigeon/messages.rb, line 16 def initialize(auth_key) self.class.headers('X-auth-key' => auth_key) end
Public Instance Methods
Sending a single transactional email
POST api.expresspigeon.com/messages
template_id: newsletter template id to be sent to: email address to send message to reply_to: email address tp reply to from: from name, such as your name or name of your organization subject: email message subject merge_fields: values for merge fields view_online: generates online version of sent message. We will host
this generated message on our servers, default is false
click_tracking: overwrites all URLs in email to point to
http://clicks.expresspigeon.com for click tracking. Setting it to false will preserve all URLs intact, but click tracking will not be available, default is true
suppress_address: if true suppresses insertion of sender's physical
address in the email, default is false
# File lib/express_pigeon/messages.rb, line 38 def send(template_id, to:, reply_to:, from:, subject:, merge_fields: {}, view_online: nil, click_tracking: nil, suppress_address: nil) options = {} options['template_id'] = template_id options['to'] = to options['from'] = from options['reply_to'] = reply_to options['subject'] = subject options['merge_fields'] = merge_fields unless merge_fields.empty? options['view_online'] = view_online unless view_online.nil? options['click_tracking'] = click_tracking unless click_tracking.nil? options['suppress_address'] = suppress_address unless suppress_address.nil? self.class.post( '', body: options.to_json, headers: { 'Content-Type' => 'application/json' } ) end
Report for a single message
GET api.expresspigeon.com/messages/{id}
# File lib/express_pigeon/messages.rb, line 60 def status(message_id) # NOTE: This appears to be sending a valid request but the response # can contain many status reports. The intent seems to be to # only return the status report for the id requested. We'll pass # along the full response for now. self.class.get('', query: { 'id' => message_id }) end
Report for multiple messages
GET api.expresspigeon.com/messages
# File lib/express_pigeon/messages.rb, line 73 def statuses(from_id: nil, start_date: nil, end_date: nil, period: nil) options = {} options['from_id'] = from_id unless from_id.nil? options['start_date'] = start_date unless start_date.nil? options['end_date'] = end_date unless end_date.nil? options['period'] = period unless period.nil? self.class.get('', query: options) end