Class: Atum::Core::Response
- Inherits:
-
Object
- Object
- Atum::Core::Response
- Defined in:
- lib/atum/core/response.rb
Instance Method Summary collapse
- #body ⇒ Object
- #error? ⇒ Boolean
- #headers ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #json? ⇒ Boolean
- #limit ⇒ Object
- #meta ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
4 5 6 |
# File 'lib/atum/core/response.rb', line 4 def initialize(response) @response = response end |
Instance Method Details
#body ⇒ Object
8 9 10 |
# File 'lib/atum/core/response.rb', line 8 def body json? ? json_body : raw_body end |
#error? ⇒ Boolean
26 27 28 |
# File 'lib/atum/core/response.rb', line 26 def error? @response.status >= 400 end |
#headers ⇒ Object
16 17 18 |
# File 'lib/atum/core/response.rb', line 16 def headers @response.headers end |
#json? ⇒ Boolean
20 21 22 23 24 |
# File 'lib/atum/core/response.rb', line 20 def json? content_type = @response.headers['Content-Type'] || @response.headers['content-type'] || '' content_type.include?('application/json') end |
#limit ⇒ Object
38 39 40 |
# File 'lib/atum/core/response.rb', line 38 def limit .fetch('limit', nil) end |
#meta ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/atum/core/response.rb', line 30 def unless json? raise ResponseError, 'Cannot fetch meta for non JSON response' end json_body.fetch('meta', {}) end |
#status ⇒ Object
12 13 14 |
# File 'lib/atum/core/response.rb', line 12 def status @response.status end |