Class: SparkPost::Transmission
- Includes:
- Request
- Defined in:
- lib/sparkpost/transmission.rb
Instance Method Summary collapse
- #endpoint ⇒ Object
-
#initialize(api_key, api_host) ⇒ Transmission
constructor
A new instance of Transmission.
- #send_message(to, from, subject, html_message = nil, **options) ⇒ Object
Methods included from Request
Constructor Details
#initialize(api_key, api_host) ⇒ Transmission
Returns a new instance of Transmission.
12 13 14 15 |
# File 'lib/sparkpost/transmission.rb', line 12 def initialize(api_key, api_host) @api_key = api_key @api_host = api_host end |
Instance Method Details
#endpoint ⇒ Object
17 18 19 |
# File 'lib/sparkpost/transmission.rb', line 17 def endpoint @api_host.concat('/api/v1/transmissions') end |
#send_message(to, from, subject, html_message = nil, **options) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/sparkpost/transmission.rb', line 21 def (to, from, subject, = nil, **) #todo add validations for to, from unless to.is_a?(Array) to = [to] end if .blank? && [:text_message].blank? fail ArgumentError, 'Content missing. Either provide html_message or text_message in options parameter' end .merge!( { recipients: prepare_recipients(to), content: { from: from, subject: subject, text: ['text_message'], html: }, options: {} } ) request(endpoint, @api_key, ) end |