Class: HanamiEmail::BaseRequest
- Inherits:
-
Object
- Object
- HanamiEmail::BaseRequest
- Defined in:
- lib/hanami_email.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #default_params ⇒ Object
-
#initialize(params = {}) ⇒ BaseRequest
constructor
A new instance of BaseRequest.
- #wrap_error(response) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ BaseRequest
Returns a new instance of BaseRequest.
23 24 25 26 27 28 29 |
# File 'lib/hanami_email.rb', line 23 def initialize(params={}) @api_key = params.delete(:api_key) || ::HanamiEmail.api_key raise ":api_key param or config option is required" unless @api_key @domain = params.delete(:domain) || ::HanamiEmail.default_domain raise ":domain param or :default_domain config option is required" unless @domain @params = params end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
21 22 23 |
# File 'lib/hanami_email.rb', line 21 def api_key @api_key end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
21 22 23 |
# File 'lib/hanami_email.rb', line 21 def domain @domain end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
21 22 23 |
# File 'lib/hanami_email.rb', line 21 def params @params end |
Instance Method Details
#default_params ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/hanami_email.rb', line 31 def default_params { timeout: ::HanamiEmail.timeout || 15, connecttimeout: ::HanamiEmail.connecttimeout || 15, followlocation: true, headers: { "Content-Type" => "application/json", "apikey" => api_key, }, } end |
#wrap_error(response) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/hanami_email.rb', line 43 def wrap_error(response) response.tap do |response| if response.timed_out? raise TimeoutError, response elsif response.code == 0 raise NoHTTPResponseError, response elsif !response.success? raise NonSuccessfulHTTPError, response end end end |