Class: KOSapiClient::HTTPClient

Inherits:
Object
  • Object
show all
Defined in:
lib/kosapi_client/http_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(http_adapter, preprocessor = ResponsePreprocessor.new, converter = ResponseConverter.new(self)) ⇒ HTTPClient

Returns a new instance of HTTPClient.



4
5
6
7
8
# File 'lib/kosapi_client/http_client.rb', line 4

def initialize(http_adapter, preprocessor = ResponsePreprocessor.new, converter = ResponseConverter.new(self))
  @http_adapter = http_adapter
  @preprocessor = preprocessor
  @converter = converter
end

Instance Method Details

#get_absolute_url(url) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/kosapi_client/http_client.rb', line 22

def get_absolute_url(url)
  if is_absolute(url)
    url
  else
    "#{@http_adapter.base_url}/#{url}"
  end
end

#process_response(result) ⇒ Object



16
17
18
19
20
# File 'lib/kosapi_client/http_client.rb', line 16

def process_response(result)
  preprocessed = @preprocessor.preprocess(result)
  response = KOSapiClient::KOSapiResponse.new(preprocessed)
  @converter.convert(response)
end

#send_request(verb, url, options = {}) ⇒ Object



10
11
12
13
14
# File 'lib/kosapi_client/http_client.rb', line 10

def send_request(verb, url, options = {})
  absolute_url = get_absolute_url(url)
  result = @http_adapter.send_request(verb, absolute_url, options)
  process_response(result)
end