Class: Mailgems::Mail
Defined Under Namespace
Classes: InvalidOption
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_version ⇒ Object
Returns the value of attribute api_version.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Mail
constructor
A new instance of Mail.
- #send_mail(params) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Mail
Returns a new instance of Mail.
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_key ⇒ Object
Returns the value of attribute api_key.
11 12 13 |
# File 'lib/mailgems/mail.rb', line 11 def api_key @api_key end |
#api_version ⇒ Object
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 |