Module: Daengine::HTTP::Client
- Defined in:
- lib/daengine/http_client.rb
Constant Summary collapse
- SLOW_CALL_THRESHOLD =
5
Class Method Summary collapse
-
.call(path, options = {}) ⇒ Object
Available options :timeout => Timeout is specified in seconds.
Class Method Details
.call(path, options = {}) ⇒ Object
Available options
:timeout => Timeout is specified in seconds.
:headers - contains string hash such has content-type: {'content-type' => 'application/xml'}
:body => Body to post.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/daengine/http_client.rb', line 15 def self.call(path, = {}) begin method = .delete(:method) || :get = {} [:timeout] = .delete(:timeout) || 10 headers = .delete(:headers) || {} headers['rake_task_name'] = (Thread.current[:rake_task_name] || 'unknown').to_s headers['visitor_id'] = (Thread.current[:visitor_id] || 'unknown').to_s headers['uuid'] ||= (Thread.current[:uuid] || 'unknown').to_s [:headers] = headers case method when :get query = [:query] || [:parameters] || [:query] = query unless query.blank? when :post, :put, :delete [:query] = [:query] if [:query] body = [:body] || [:parameters] || [:body] = body else raise ArgumentError.new('you must specify a method of either :get, :post, :put, or :delete') end start = Time.now resp = HTTParty.send(method.to_sym, path, ) elapsed = Time.now - start Daengine.log("***** Daengine::HTTP::Client.call(#{method}, #{path}, #{}) TOOK #{elapsed} seconds +++++++++++++++++++++", elapsed > SLOW_CALL_THRESHOLD ? 'warn' : 'info') rescue => ex Daengine.log("Error calling service (#{path}) - #{ex.inspect}\n#{ex.backtrace.join("\n\t")}", 'error') #raise ex end Response.new(resp) end |