lib/ezclient/request.rb in ezclient-0.1.0 vs lib/ezclient/request.rb in ezclient-0.2.0

- old
+ new

@@ -1,10 +1,8 @@ # frozen_string_literal: true class EzClient::Request - DEFAULT_TIMEOUT = 15 - attr_accessor :verb, :url, :options def initialize(verb, url, options) self.verb = verb.to_s.upcase self.url = url @@ -40,22 +38,27 @@ end private def http_client - options.fetch(:client).timeout(timeout) + @http_client ||= begin + client = options.fetch(:client) + client.timeout(timeout) if timeout + client + end end - def timeout - options.fetch(:timeout, DEFAULT_TIMEOUT).to_f - end - def http_request @http_request ||= http_client.build_request(verb, url, http_options) end def http_options - options.slice(:params, :form, :json, :body, :headers) + # RUBY25: Hash#slice + options.select { |key| [:params, :form, :json, :body, :headers].include?(key) } + end + + def timeout + options[:timeout] end def on_complete options[:on_complete] || proc {} end