Class: Appfirst::Response
- Inherits:
-
Object
- Object
- Appfirst::Response
- Defined in:
- lib/appfirst/response.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- BadRequest =
Class.new(Error)
- NotFound =
Class.new(Error)
- Unprocessable =
Class.new(Error)
- Conflict =
Class.new(Error)
- Unexpected =
Class.new(Error)
- EXCEPTION_MAPPING =
{ 400 => BadRequest, 404 => NotFound, 409 => Conflict, 422 => Unprocessable, 500 => Unexpected, }
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(status, headers, body) ⇒ Response
constructor
A new instance of Response.
- #raise! ⇒ Object
- #successful? ⇒ Boolean
Constructor Details
#initialize(status, headers, body) ⇒ Response
Returns a new instance of Response.
27 28 29 |
# File 'lib/appfirst/response.rb', line 27 def initialize(status, headers, body) @status, @headers, @body = status, headers, body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
25 26 27 |
# File 'lib/appfirst/response.rb', line 25 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
25 26 27 |
# File 'lib/appfirst/response.rb', line 25 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
25 26 27 |
# File 'lib/appfirst/response.rb', line 25 def status @status end |
Instance Method Details
#raise! ⇒ Object
35 36 37 38 39 40 |
# File 'lib/appfirst/response.rb', line 35 def raise! if !successful? raise (EXCEPTION_MAPPING[self.status] || Error).new(self) else self end end |
#successful? ⇒ Boolean
31 32 33 |
# File 'lib/appfirst/response.rb', line 31 def successful? self.status < 300 && self.status > 199 || self.status == 304 end |