Class: DMCourier::Services::Sparkpost
- Inherits:
-
Object
- Object
- DMCourier::Services::Sparkpost
- Includes:
- MessageHelper
- Defined in:
- lib/dm_courier/services/sparkpost.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#mail ⇒ Object
readonly
Returns the value of attribute mail.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #deliver! ⇒ Object
-
#initialize(mail, options = {}) ⇒ Sparkpost
constructor
A new instance of Sparkpost.
- #name ⇒ Object
- #sparkpost_message ⇒ Object
Methods included from MessageHelper
#attachments, #attachments?, #extract_params, #fallback_options, #from, #from_address, #from_email, #from_name, #html_part, #nil_true_false?, #return_string_value, #subject, #text_part
Constructor Details
#initialize(mail, options = {}) ⇒ Sparkpost
Returns a new instance of Sparkpost.
14 15 16 17 18 |
# File 'lib/dm_courier/services/sparkpost.rb', line 14 def initialize(mail, = {}) @mail = mail @api_key = .fetch(:api_key) @options = end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
12 13 14 |
# File 'lib/dm_courier/services/sparkpost.rb', line 12 def api_key @api_key end |
#mail ⇒ Object (readonly)
Returns the value of attribute mail.
12 13 14 |
# File 'lib/dm_courier/services/sparkpost.rb', line 12 def mail @mail end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/dm_courier/services/sparkpost.rb', line 12 def @options end |
Instance Method Details
#deliver! ⇒ Object
24 25 26 27 28 29 |
# File 'lib/dm_courier/services/sparkpost.rb', line 24 def deliver! sparkpost = ::SparkPost::Client.new(api_key) transmission = sparkpost.transmission transmission.send(:request, transmission.endpoint, api_key, ) end |
#name ⇒ Object
20 21 22 |
# File 'lib/dm_courier/services/sparkpost.rb', line 20 def name :sparkpost end |
#sparkpost_message ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/dm_courier/services/sparkpost.rb', line 31 def parameters = extract_params(nil_true_false: { inline_css: :inline_css, click_tracking: :track_clicks, open_tracking: :track_opens }, string: { return_path: :return_path_domain }) = { options: {} } [:options][:inline_css] = parameters[:inline_css] unless parameters[:inline_css].nil? [:options][:click_tracking] = parameters[:click_tracking] unless parameters[:click_tracking].nil? [:options][:open_tracking] = parameters[:open_tracking] unless parameters[:open_tracking].nil? [:return_path] = parameters[:return_path] unless parameters[:return_path].nil? from = { email: from_email } from[:name] = from_name if from_name [:content] = { from: from, subject: subject } [:content][:reply_to] = reply_to if reply_to [:content][:html] = html_part if html_part [:content][:text] = text_part if text_part [:recipients] = recipients [:content][:attachments] = if (inline: false) [:content][:inline_images] = if (inline: true) end |