Class: SimpleSpark::Endpoints::Transmissions
- Inherits:
-
Object
- Object
- SimpleSpark::Endpoints::Transmissions
- Defined in:
- lib/simple_spark/endpoints/transmissions.rb
Overview
Provides access to the /transmissions endpoint See: developers.sparkpost.com/api/#/reference/transmissions
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
-
#create(values, num_rcpt_errors = nil) ⇒ Object
Sends an email message Or to use a template, change the content key to be: content: { template_id: ‘first-template-id’ }.
-
#delete_campaign(campaign_id) ⇒ Object
Deletes all transmissions for a given campaign.
-
#initialize(client) ⇒ Transmissions
constructor
A new instance of Transmissions.
-
#list(campaign_id = nil, template_id = nil) ⇒ Object
Sends an email message.
Constructor Details
#initialize(client) ⇒ Transmissions
Returns a new instance of Transmissions.
8 9 10 |
# File 'lib/simple_spark/endpoints/transmissions.rb', line 8 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
6 7 8 |
# File 'lib/simple_spark/endpoints/transmissions.rb', line 6 def client @client end |
Instance Method Details
#create(values, num_rcpt_errors = nil) ⇒ Object
Note:
Example: properties = {
options: { open_tracking: true, click_tracking: true },
campaign_id: 'christmas_campaign',
return_path: '[email protected]',
metadata: {user_type: 'students'},
substitution_data: { sender: 'Big Store Team' },
recipients: [
{ address: { email: '[email protected]', name: 'Your Customer' },
tags: ['greeting', 'sales'],
metadata: { place: 'Earth' }, substitution_data: { address: '123 Their Road' } }
],
content:
{ from: { name: 'Your Name', email: '[email protected]' },
subject: 'I am a test email',
reply_to: 'Sales <[email protected]>',
headers: { 'X-Customer-CampaignID' => 'christmas_campaign' },
text: 'Hi from {{sender}} ... this is a test, and here is your address {{address}}',
html: '<p>Hi from {{sender}}</p><p>This is a test</p>'
}
}
Sends an email message Or to use a template, change the content key to be: content: { template_id: ‘first-template-id’ }
41 42 43 44 |
# File 'lib/simple_spark/endpoints/transmissions.rb', line 41 def create(values, num_rcpt_errors = nil) query_params = num_rcpt_errors.nil? ? {} : { num_rcpt_errors: num_rcpt_errors } @client.call(method: :post, path: 'transmissions', body_values: values, query_values: query_params) end |
#delete_campaign(campaign_id) ⇒ Object
Note:
Endpoint returns empty response body with 204 status code
Deletes all transmissions for a given campaign
63 64 65 |
# File 'lib/simple_spark/endpoints/transmissions.rb', line 63 def delete_campaign(campaign_id) @client.call(method: :delete, path: 'transmissions', query_values: { campaign_id: campaign_id }) end |
#list(campaign_id = nil, template_id = nil) ⇒ Object
Sends an email message
52 53 54 55 56 57 |
# File 'lib/simple_spark/endpoints/transmissions.rb', line 52 def list(campaign_id = nil, template_id = nil) query_params = {} query_params[:campaign_id] = campaign_id if campaign_id query_params[:template_id] = template_id if template_id @client.call(method: :get, path: 'transmissions', query_values: query_params) end |