Class: CampaignHQ::API::Response
- Inherits:
-
Object
- Object
- CampaignHQ::API::Response
- Defined in:
- lib/campaign_h_q/api/response.rb
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.
13 14 15 16 |
# File 'lib/campaign_h_q/api/response.rb', line 13 def initialize(response) @raw = response raise error_class, self if error? end |
Instance Method Details
#body ⇒ Object
34 35 36 |
# File 'lib/campaign_h_q/api/response.rb', line 34 def body JSON.parse @raw.body end |
#error? ⇒ Boolean
30 31 32 |
# File 'lib/campaign_h_q/api/response.rb', line 30 def error? !success? end |
#error_class ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/campaign_h_q/api/response.rb', line 38 def error_class return unless error? case body['error'] when 'unprocessable_entity' Error::InvalidParameters when 'unauthorized' Error::Unauthorized when 'not_found' Error::NotFound else Error end end |
#headers ⇒ Object
22 23 24 |
# File 'lib/campaign_h_q/api/response.rb', line 22 def headers @raw.headers end |
#status ⇒ Object
18 19 20 |
# File 'lib/campaign_h_q/api/response.rb', line 18 def status @raw.status end |
#success? ⇒ Boolean
26 27 28 |
# File 'lib/campaign_h_q/api/response.rb', line 26 def success? @raw.is_a? Net::HTTPSuccess end |