lib/ezclient/request.rb in ezclient-0.14.0 vs lib/ezclient/request.rb in ezclient-0.15.0
- old
+ new
@@ -73,10 +73,11 @@
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[:form] = prepare_form_params(opts[:form]) if opts[:form]
opts[:headers] = prepare_headers(options[:headers])
http_client.build_request(verb, url, opts)
end
end
@@ -146,9 +147,19 @@
def prepare_headers(headers)
headers = HTTP::Headers.coerce(headers)
headers[:user_agent] ||= "ezclient/#{EzClient::VERSION}"
headers
+ end
+
+ def prepare_form_params(params)
+ params.transform_values do |value|
+ if value.is_a?(File)
+ HTTP::FormData::File.new(value)
+ else
+ value
+ end
+ end
end
def set_timeout(client)
return client unless timeout