Class: KcoRuby::ResponseHandler

Inherits:
Object
  • Object
show all
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

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

#dataObject



25
26
27
# File 'lib/kco_ruby/response_handler.rb', line 25

def data
  @response.body.strip
end

#handle_responseObject



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

#locationObject



21
22
23
# File 'lib/kco_ruby/response_handler.rb', line 21

def location
  @response['location']
end