Class: KcoRuby::ResponseHandler
- Inherits:
-
Object
- Object
- KcoRuby::ResponseHandler
- Defined in:
- lib/kco_ruby/response_handler.rb
Overview
When a Response is created this class describe all actions that needs to happen with that response
Instance Method Summary collapse
- #data ⇒ Object
- #handle_response ⇒ Object
-
#initialize(response, resource) ⇒ ResponseHandler
constructor
A new instance of ResponseHandler.
- #location ⇒ Object
Constructor Details
#initialize(response, resource) ⇒ ResponseHandler
Returns a new instance of ResponseHandler.
5 6 7 8 |
# File 'lib/kco_ruby/response_handler.rb', line 5 def initialize(response, resource) @resource = resource @response = response end |
Instance Method Details
#data ⇒ Object
25 26 27 |
# File 'lib/kco_ruby/response_handler.rb', line 25 def data @response.body.strip end |
#handle_response ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/kco_ruby/response_handler.rb', line 10 def handle_response case @response when Net::HTTPOK update_resource_data when Net::HTTPCreated update_resource_location else raise Exception.new("Invalid response #{@response.inspect}") end end |
#location ⇒ Object
21 22 23 |
# File 'lib/kco_ruby/response_handler.rb', line 21 def location @response['location'] end |