Class: SparkPost::Transmission

Inherits:
Object
  • Object
show all
Includes:
Request
Defined in:
lib/sparkpost/transmission.rb

Instance Method Summary collapse

Methods included from Request

process_response, 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

#endpointObject



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 send_message(to, from, subject, html_message = nil, **options)
  #todo add validations for to, from
  unless to.is_a?(Array)
    to = [to]
  end

  if html_message.blank? && options[:text_message].blank?
    fail ArgumentError, 'Content missing. Either provide html_message or text_message in options parameter'
  end

  options.merge!(
      {
          recipients: prepare_recipients(to),
          content: {
              from: from,
              subject: subject,
              text: options['text_message'],
              html: html_message
          },
          options: {}
      }
  )

  request(endpoint, @api_key, options)
end