lib/ezclient/request.rb in ezclient-0.11.0 vs lib/ezclient/request.rb in ezclient-0.12.0

- old
+ new

@@ -66,15 +66,18 @@ attr_accessor :client def http_request @http_request ||= begin - # RUBY25: Hash#slice - opts = options.select { |key| [:json, :body, :headers].include?(key) } + opts = {} + opts[verb == "GET" ? :params : :form] = options[:params] + opts[:json] = options[:json] if options[:json] + opts[:body] = options[:body] if options[:body] opts[:params] = options[:query] if options[:query] opts[:form] = options[:form] if options[:form] + opts[:headers] = prepare_headers(options[:headers]) http_client.build_request(verb, url, opts) end end @@ -136,9 +139,15 @@ Array(options[:retry_exceptions]) end def max_retries options[:max_retries] || 1 + end + + def prepare_headers(headers) + headers = HTTP::Headers.coerce(headers) + headers[:user_agent] ||= "ezclient/#{EzClient::VERSION}" + headers end def basic_auth @basic_auth ||= begin case options[:basic_auth]