Class: EmailOctopus::API::Response
- Inherits:
-
Object
- Object
- EmailOctopus::API::Response
- Defined in:
- lib/email_octopus/api/response.rb
Overview
Response object that parses out JSON.
Instance Method Summary collapse
- #body ⇒ Object
- #error? ⇒ Boolean
- #error_class ⇒ Object
- #headers ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #status ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
9 10 11 12 |
# File 'lib/email_octopus/api/response.rb', line 9 def initialize(response) @raw = response raise error_class, self if error? end |
Instance Method Details
#body ⇒ Object
30 31 32 |
# File 'lib/email_octopus/api/response.rb', line 30 def body JSON.parse @raw.body end |
#error? ⇒ Boolean
26 27 28 |
# File 'lib/email_octopus/api/response.rb', line 26 def error? !success? end |
#error_class ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/email_octopus/api/response.rb', line 34 def error_class return unless error? case body['code'] when 'INVALID_PARAMETERS' Error::InvalidParameters when 'API_KEY_INVALID' Error::ApiKeyInvalid when 'UNAUTHORISED' Error::Unauthorized when 'NOT_FOUND' Error::NotFound else Error end end |
#headers ⇒ Object
18 19 20 |
# File 'lib/email_octopus/api/response.rb', line 18 def headers @raw.headers end |
#status ⇒ Object
14 15 16 |
# File 'lib/email_octopus/api/response.rb', line 14 def status @raw.status end |
#success? ⇒ Boolean
22 23 24 |
# File 'lib/email_octopus/api/response.rb', line 22 def success? @raw.is_a? Net::HTTPSuccess end |