Class: Imgur::Response
- Inherits:
-
Object
- Object
- Imgur::Response
- Defined in:
- lib/imgur/response.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- BadRequest =
Class.new(Error)
- NotFound =
Class.new(Error)
- Forbidden =
Class.new(Error)
- Unprocessable =
Class.new(Error)
- EXCEPTION_MAPPING =
{ 400 => BadRequest, 403 => Forbidden, 404 => NotFound, 422 => Unprocessable, }
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.
24 25 26 |
# File 'lib/imgur/response.rb', line 24 def initialize(status, headers, body) @status, @headers, @body = status, headers, body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
22 23 24 |
# File 'lib/imgur/response.rb', line 22 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
22 23 24 |
# File 'lib/imgur/response.rb', line 22 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
22 23 24 |
# File 'lib/imgur/response.rb', line 22 def status @status end |
Instance Method Details
#raise! ⇒ Object
32 33 34 35 36 37 |
# File 'lib/imgur/response.rb', line 32 def raise! if klass = EXCEPTION_MAPPING[self.status.to_i] raise klass.new(self) else self end end |
#successful? ⇒ Boolean
28 29 30 |
# File 'lib/imgur/response.rb', line 28 def successful? self.status.to_i < 300 && self.status.to_i > 199 end |