lib/ezclient/request.rb in ezclient-1.5.1 vs lib/ezclient/request.rb in ezclient-1.6.0
- old
+ new
@@ -8,11 +8,11 @@
metadata
params
query
].freeze
- attr_accessor :verb, :url, :options
+ attr_accessor :verb, :url, :options, :elapsed_seconds
def initialize(verb, url, options)
self.verb = verb.to_s.upcase
self.url = url
self.client = options.delete(:client)
@@ -99,19 +99,22 @@
http_client
end
end
def perform_request
+ perform_started_at = EzClient.get_time
with_retry do
# Use original client so that connection can be reused
res = client.perform(http_request, http_options)
return res unless follow
HTTP::Redirector.new(follow).perform(http_request, res) do |request|
client.perform(request, http_options)
end
end
+ ensure
+ self.elapsed_seconds = EzClient.get_time - perform_started_at
end
def with_retry(&block)
retries = 0
@@ -196,16 +199,15 @@
def set_timeout(client)
timeout ? client.timeout(timeout) : client
end
def basic_auth
- @basic_auth ||= begin
+ @basic_auth ||=
case options[:basic_auth]
when Array
user, password = options[:basic_auth]
{ user: user, pass: password }
when Hash
options[:basic_auth]
end
- end
end
end