Class: ElasticEmail::Deliverer

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_email/deliverer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ Deliverer

Returns a new instance of Deliverer.



6
7
8
# File 'lib/elastic_email/deliverer.rb', line 6

def initialize(settings)
  self.settings = settings
end

Instance Attribute Details

#settingsObject

Returns the value of attribute settings.



4
5
6
# File 'lib/elastic_email/deliverer.rb', line 4

def settings
  @settings
end

Instance Method Details

#api_keyObject



14
15
16
# File 'lib/elastic_email/deliverer.rb', line 14

def api_key
  self.settings[:api_key]
end

#deliver!(rails_message) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/elastic_email/deliverer.rb', line 18

def deliver!(rails_message)
  response = elastic_email_client.send_message build_elastic_email_message_for(rails_message)
  response_body = response.body
  if response.code == '200' and response_body.match('^[0-9|a-f]{8}-[0-9|a-f]{4}-[0-9|a-f]{4}-[0-9|a-f]{4}-[0-9|a-f]{12}$').present?
    rails_message.message_id = response_body
  else
    raise Error.new(response_body)
  end
  response
end

#usernameObject



10
11
12
# File 'lib/elastic_email/deliverer.rb', line 10

def username
  self.settings[:username]
end