Class: T::Mailer::Api::SparkPost::Transmissions

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/t/mailer/api/spark_post.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • options (Hash)

    with the credentials



16
17
18
19
20
# File 'lib/t/mailer/api/spark_post.rb', line 16

def initialize(options)
  @settings = options

  check_settings(:sparkpost_api_key)
end

Instance Attribute Details

#settingsObject (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

#clientObject

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"
}

}

Parameters:

  • attrs (Hash)

    with the details of the email

Returns:

  • (Hash)

    with the server response



69
70
71
# File 'lib/t/mailer/api/spark_post.rb', line 69

def create(attrs)
  client.transmissions.create(attrs)
end