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
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #json? ⇒ Boolean
- #limit ⇒ Object
- #meta ⇒ 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? ? handle_json : handle_raw end |
#error? ⇒ Boolean
18 19 20 |
# File 'lib/atum/core/response.rb', line 18 def error? @response.status >= 400 end |
#json? ⇒ Boolean
12 13 14 15 16 |
# File 'lib/atum/core/response.rb', line 12 def json? content_type = @response.headers['Content-Type'] || @response.headers['content-type'] || '' content_type.include?('application/json') end |
#limit ⇒ Object
30 31 32 |
# File 'lib/atum/core/response.rb', line 30 def limit .fetch('limit', nil) end |
#meta ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/atum/core/response.rb', line 22 def unless json? raise ResponseError, 'Cannot fetch meta for non JSON response' end json_body.fetch('meta', {}) end |