Class: Fulfillment::Response
- Inherits:
-
Object
- Object
- Fulfillment::Response
- Extended by:
- Forwardable
- Defined in:
- lib/fulfillment/response.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#raw_response ⇒ Object
readonly
Returns the value of attribute raw_response.
Instance Method Summary collapse
-
#initialize(raw_response) ⇒ Response
constructor
A new instance of Response.
- #on_error {|_self| ... } ⇒ Object
- #raise_errors ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(raw_response) ⇒ Response
Returns a new instance of Response.
9 10 11 |
# File 'lib/fulfillment/response.rb', line 9 def initialize(raw_response) @raw_response = raw_response end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
5 6 7 |
# File 'lib/fulfillment/response.rb', line 5 def errors @errors end |
#raw_response ⇒ Object (readonly)
Returns the value of attribute raw_response.
5 6 7 |
# File 'lib/fulfillment/response.rb', line 5 def raw_response @raw_response end |
Instance Method Details
#on_error {|_self| ... } ⇒ Object
17 18 19 20 |
# File 'lib/fulfillment/response.rb', line 17 def on_error yield self unless success? self end |
#raise_errors ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fulfillment/response.rb', line 22 def raise_errors case status when 400 fail InvalidRequest, body when 401 fail AccessDenied, body when 403 fail InvalidEvent, body when 404 fail ResourceNotFound, body when 405 fail MethodNotAllowed, body when (400..499) fail ServiceError, body when (500..599) fail ServerError, body end end |
#success? ⇒ Boolean
13 14 15 |
# File 'lib/fulfillment/response.rb', line 13 def success? (200..299).include?(status) end |