Class: T::Mailer::Api::SparkPost::Transmissions
- Inherits:
-
Object
- Object
- T::Mailer::Api::SparkPost::Transmissions
- Includes:
- Helper
- Defined in:
- lib/t/mailer/api/spark_post.rb
Instance Attribute Summary collapse
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
-
#client ⇒ Object
Creates a client which will connect to server via API.
-
#create(attrs) ⇒ Hash
The following attribute should be set in the content object when sending RFC822 content as the transmission’s content:.
-
#initialize(options) ⇒ Transmissions
constructor
Set settings and check if the required credential exists.
Methods included from Helper
#check_api_defined, #check_settings, #check_version_of, #field_value, #get_value_from, #using_gem
Constructor Details
#initialize(options) ⇒ Transmissions
Set settings and check if the required credential exists. If the credential is missing then it will raise error.
16 17 18 19 20 |
# File 'lib/t/mailer/api/spark_post.rb', line 16 def initialize() @settings = check_settings(:sparkpost_api_key) end |
Instance Attribute Details
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
10 11 12 |
# File 'lib/t/mailer/api/spark_post.rb', line 10 def settings @settings end |
Instance Method Details
#client ⇒ Object
Creates a client which will connect to server via API
23 24 25 |
# File 'lib/t/mailer/api/spark_post.rb', line 23 def client SimpleSpark::Client.new(api_key: settings[:sparkpost_api_key]) end |
#create(attrs) ⇒ Hash
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": "[email protected]",
"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"
}
}
69 70 71 |
# File 'lib/t/mailer/api/spark_post.rb', line 69 def create(attrs) client.transmissions.create(attrs) end |