class T::Mailer::Api::SparkPost::Transmissions
Attributes
settings[R]
Public Class Methods
new(options)
click to toggle source
Set settings and check if the required credential exists. If the credential is missing then it will raise error.
@param [Hash] options with the credentials
# File lib/t/mailer/api/spark_post.rb, line 16 def initialize(options) @settings = options check_settings(:sparkpost_api_key) end
Public Instance Methods
client()
click to toggle source
Creates a client which will connect to server via API
# File lib/t/mailer/api/spark_post.rb, line 23 def client SimpleSpark::Client.new(api_key: settings[:sparkpost_api_key]) end
create(attrs)
click to toggle source
The following attribute should be set in the content object when sending RFC822 content as the transmission's content:
Request
POST /api/v1/transmissions/{?num_rcpt_errors} {
"description": "Christmas Campaign Email", "recipients": [ { "address": { "email": "wilma@flintstone.com", "name": "Wilma Flintstone" }, "substitution_data": { "first_name": "Wilma", "customer_type": "Platinum", "year": "Freshman" } } ], "content": { "email_rfc822": "Content-Type: text/plain\r\nTo: \"{{address.name}}\" <{{address.email}}>\r\n\r\n Hi {{first_name}} \nSave big this Christmas in your area {{place}}! \nClick http://www.mysite.com and get huge discount\n Hurry, this offer is only to {{customer_type}}\n {{sender}}\r\n" }
} Response
{
"results": { "total_rejected_recipients": 0, "total_accepted_recipients": 2, "id": "11668787484950529" }
}
@param [Hash] attrs with the details of the email
@return [Hash] with the server response
# File lib/t/mailer/api/spark_post.rb, line 69 def create(attrs) client.transmissions.create(attrs) end