Class: Plangrade::ApiResponse
- Inherits:
-
Object
- Object
- Plangrade::ApiResponse
- Defined in:
- lib/plangrade/api_response.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
- #body ⇒ Object
- #created? ⇒ Boolean
- #empty? ⇒ Boolean
-
#initialize(headers, body, code) ⇒ ApiResponse
constructor
A new instance of ApiResponse.
- #raw_body ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(headers, body, code) ⇒ ApiResponse
Returns a new instance of ApiResponse.
6 7 8 9 10 |
# File 'lib/plangrade/api_response.rb', line 6 def initialize(headers, body, code) @headers = headers @body = body @code = code.to_i end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
4 5 6 |
# File 'lib/plangrade/api_response.rb', line 4 def code @code end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
4 5 6 |
# File 'lib/plangrade/api_response.rb', line 4 def headers @headers end |
Instance Method Details
#body ⇒ Object
16 17 18 |
# File 'lib/plangrade/api_response.rb', line 16 def body @parsed_body ||= parse(@body) end |
#created? ⇒ Boolean
28 29 30 |
# File 'lib/plangrade/api_response.rb', line 28 def created? @code == 201 end |
#empty? ⇒ Boolean
20 21 22 |
# File 'lib/plangrade/api_response.rb', line 20 def empty? @body.nil? || @body.strip.empty? end |
#raw_body ⇒ Object
12 13 14 |
# File 'lib/plangrade/api_response.rb', line 12 def raw_body @body end |
#success? ⇒ Boolean
24 25 26 |
# File 'lib/plangrade/api_response.rb', line 24 def success? @code == 200 end |