Class: Knowtify::ExconHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/knowtify/handlers/excon_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExconHandler

Returns a new instance of ExconHandler.



7
8
9
10
11
12
13
14
# File 'lib/knowtify/handlers/excon_handler.rb', line 7

def initialize
  opts = {
    :idempotent => true,
    :retry_limit => config.max_retries
  }.merge(config.http_client_options)
  opts[:instrumentor] = Excon::StandardInstrumentor if config.debug? # output full request data if debugging
  @http_client = Excon.new(config.base_url,opts)
end

Instance Attribute Details

#http_clientObject

Returns the value of attribute http_client.



5
6
7
# File 'lib/knowtify/handlers/excon_handler.rb', line 5

def http_client
  @http_client
end

Instance Method Details

#configObject



34
35
36
# File 'lib/knowtify/handlers/excon_handler.rb', line 34

def config
  Knowtify.config
end

#post(request, count = 0) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/knowtify/handlers/excon_handler.rb', line 22

def post(request,count=0)
  resp = Knowtify::Response.new(count)
  resp.raw_response = http_client.post(request_options(request))
  resp.body = resp.raw_response.body
  resp.http_code = resp.raw_response.status
  if resp.retry?
    post(request,count + 1)
  else
    resp
  end
end

#request_options(request) ⇒ Object



16
17
18
19
20
# File 'lib/knowtify/handlers/excon_handler.rb', line 16

def request_options(request)
  {:path => request.path,
   :body => request.params.to_json,
   :headers => request.headers}.merge(request.http_request_options)
end