Class: Ey::Core::Response
- Inherits:
-
Object
- Object
- Ey::Core::Response
- Defined in:
- lib/ey-core/response.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- BadRequest =
Class.new(Error)
- Conflict =
Class.new(Error)
- NotFound =
Class.new(Error)
- RateLimitExceeded =
Class.new(Error)
Class.new(Error)
- Unexpected =
Class.new(Error)
- Unprocessable =
Class.new(Error)
- EXCEPTION_MAPPING =
{ 400 => BadRequest, 401 => Unauthorized, 404 => NotFound, 409 => Conflict, 422 => Unprocessable, 429 => RateLimitExceeded, 500 => Unexpected, }
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Response
constructor
A new instance of Response.
- #raise! ⇒ Object
- #successful? ⇒ Boolean
Constructor Details
#initialize(opts = {}) ⇒ Response
Returns a new instance of Response.
42 43 44 45 46 47 |
# File 'lib/ey-core/response.rb', line 42 def initialize(opts = {}) @status = opts[:status] @headers = opts[:headers] @body = opts[:body] @request = opts[:request] end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
40 41 42 |
# File 'lib/ey-core/response.rb', line 40 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
40 41 42 |
# File 'lib/ey-core/response.rb', line 40 def headers @headers end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
40 41 42 |
# File 'lib/ey-core/response.rb', line 40 def request @request end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
40 41 42 |
# File 'lib/ey-core/response.rb', line 40 def status @status end |
Instance Method Details
#raise! ⇒ Object
53 54 55 56 57 58 |
# File 'lib/ey-core/response.rb', line 53 def raise! if !successful? raise (EXCEPTION_MAPPING[self.status] || Error).new(self) else self end end |
#successful? ⇒ Boolean
49 50 51 |
# File 'lib/ey-core/response.rb', line 49 def successful? self.status >= 200 && self.status <= 299 || self.status == 304 end |