Class: Mailstro::Delivery

Inherits:
Object
  • Object
show all
Defined in:
lib/mailstro/delivery.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, options) ⇒ Delivery

Returns a new instance of Delivery.



13
14
15
16
17
# File 'lib/mailstro/delivery.rb', line 13

def initialize(template, options)
  @template  = template
  @recipient = options[:recipient]
  @payload   = options[:payload]
end

Instance Attribute Details

#payloadObject (readonly)

Returns the value of attribute payload.



7
8
9
# File 'lib/mailstro/delivery.rb', line 7

def payload
  @payload
end

#recipientObject (readonly)

Returns the value of attribute recipient.



7
8
9
# File 'lib/mailstro/delivery.rb', line 7

def recipient
  @recipient
end

#templateObject (readonly)

Returns the value of attribute template.



7
8
9
# File 'lib/mailstro/delivery.rb', line 7

def template
  @template
end

Class Method Details

.deliver(*args) ⇒ Object



9
10
11
# File 'lib/mailstro/delivery.rb', line 9

def self.deliver(*args)
  new(*args).deliver
end

Instance Method Details

#deliverObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mailstro/delivery.rb', line 19

def deliver
  http             = Net::HTTP.new(endpoint_uri.host, endpoint_uri.port)
  http.use_ssl     = endpoint_uri.scheme == "https"
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  request      = Net::HTTP::Post.new(endpoint_uri.request_uri, { 'Content-Type' =>'application/json' })
  request.body = JSON.generate(post_data)

  response = http.request(request)

  # response.status
  # response["header-here"] # All headers are lowercase

  JSON.parse(response.body)
end