Class: Mailgems::Mail

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/mailgems/mail.rb

Defined Under Namespace

Classes: InvalidOption

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Mail

Returns a new instance of Mail.

Raises:



13
14
15
16
17
18
# File 'lib/mailgems/mail.rb', line 13

def initialize(opts = {})
  @api_key = opts[:api_key]
  @api_version = opts[:api_version] || 'v1'

  raise InvalidOption, "Api Key is required" if opts[:api_key].nil?
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



11
12
13
# File 'lib/mailgems/mail.rb', line 11

def api_key
  @api_key
end

#api_versionObject

Returns the value of attribute api_version.



11
12
13
# File 'lib/mailgems/mail.rb', line 11

def api_version
  @api_version
end

Instance Method Details

#send_mail(params) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mailgems/mail.rb', line 20

def send_mail(params)
  response = self.class.post("/#{api_version}/emails",
                             body: params.to_json, headers: headers)

  response_code = response.code
  response_hash = response.parsed_response

  raise_exception(response_code, response_hash) unless response_code == 200

  response_hash
end