Class: Boxxspring::Response
- Inherits:
-
Object
- Object
- Boxxspring::Response
- Defined in:
- lib/boxxspring/response.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
Instance Method Summary collapse
- #failure? ⇒ Boolean
-
#initialize(http_response) ⇒ Response
constructor
A new instance of Response.
- #success? ⇒ Boolean
Constructor Details
#initialize(http_response) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/boxxspring/response.rb', line 9 def initialize( http_response ) @code = http_response.code @content = decode_response_body( http_response ) error = @content.respond_to?( :keys ) ? @content[ 'errors' ] : nil if @content.respond_to?( :include? ) && @content.include?( 'errors' ) @error = Boxxspring::Error.new( @content[ 'errors' ][ 'message' ] ) end @success = http_response.is_a?( Net::HTTPOK ) && @content.present? && @error.nil? @error = Boxxspring::Error.new( 'unknown' ) \ if !@success && @error.nil? end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
7 8 9 |
# File 'lib/boxxspring/response.rb', line 7 def code @code end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
5 6 7 |
# File 'lib/boxxspring/response.rb', line 5 def content @content end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
6 7 8 |
# File 'lib/boxxspring/response.rb', line 6 def error @error end |
Instance Method Details
#failure? ⇒ Boolean
34 35 36 |
# File 'lib/boxxspring/response.rb', line 34 def failure? not @success end |
#success? ⇒ Boolean
30 31 32 |
# File 'lib/boxxspring/response.rb', line 30 def success? @success end |