Class: T::Mailer::DeliverySystem::SparkPost
- Inherits:
-
Object
- Object
- T::Mailer::DeliverySystem::SparkPost
- Includes:
- Helper
- Defined in:
- lib/t/mailer/delivery_system/spark_post.rb
Instance Attribute Summary collapse
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
-
#deliver(message) ⇒ Mail::Message
Check that the API is loaded.
-
#generate_options(message) ⇒ Hash
Generate the required hash what it will send via API.
-
#generate_recipients(message) ⇒ Array
Generate recipients.
-
#initialize(options = {}) ⇒ SparkPost
constructor
Set settings with the required credentials for the API, but allow to call this delivery system without it.
Methods included from Helper
#check_api_defined, #check_settings, #check_version_of, #field_value, #get_value_from, #using_gem
Constructor Details
#initialize(options = {}) ⇒ SparkPost
Set settings with the required credentials for the API, but allow to call this delivery system without it.
13 14 15 |
# File 'lib/t/mailer/delivery_system/spark_post.rb', line 13 def initialize( = {}) @settings = end |
Instance Attribute Details
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
7 8 9 |
# File 'lib/t/mailer/delivery_system/spark_post.rb', line 7 def settings @settings end |
Instance Method Details
#deliver(message) ⇒ Mail::Message
Check that the API is loaded. If API is missing it will raise error. If API exists then it will call the API with the generated options from the given mail message.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/t/mailer/delivery_system/spark_post.rb', line 24 def deliver() check_api_defined("Api::SparkPost::Transmissions") = () response = Api::SparkPost::Transmissions.new(settings).create() . = response && response.dig("id") end |
#generate_options(message) ⇒ Hash
Generate the required hash what it will send via API.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/t/mailer/delivery_system/spark_post.rb', line 40 def () { options: get_value_from(["options"]), campaign_id: get_value_from(["tag"]), content: { email_rfc822: .to_s, }, metadata: get_value_from(["metadata"]), recipients: generate_recipients(), } end |
#generate_recipients(message) ⇒ Array
Generate recipients.
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/t/mailer/delivery_system/spark_post.rb', line 57 def generate_recipients() .to.map do |to| { address: { email: to, }, tags: [ get_value_from(["tag"]), ], } end end |