mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
enable url parameters for all actions. Closes #53
This commit is contained in:
parent
60145b3f9c
commit
1060baed79
2 changed files with 14 additions and 17 deletions
|
@ -1,6 +1,7 @@
|
||||||
# 1.6.5
|
# 1.6.5
|
||||||
|
|
||||||
- RFC6265 requires single SP after ';' for separating parameters pairs in the 'Cookie:' header (patch provided by Hiroshi Nakamura)
|
- RFC6265 requires single SP after ';' for separating parameters pairs in the 'Cookie:' header (patch provided by Hiroshi Nakamura)
|
||||||
|
- enable url parameters for all actions
|
||||||
|
|
||||||
# 1.6.4
|
# 1.6.4
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ module RestClient
|
||||||
@method = args[:method] or raise ArgumentError, "must pass :method"
|
@method = args[:method] or raise ArgumentError, "must pass :method"
|
||||||
@headers = args[:headers] || {}
|
@headers = args[:headers] || {}
|
||||||
if args[:url]
|
if args[:url]
|
||||||
@url = process_get_params(args[:url], headers)
|
@url = process_url_params(args[:url], headers)
|
||||||
else
|
else
|
||||||
raise ArgumentError, "must pass :url"
|
raise ArgumentError, "must pass :url"
|
||||||
end
|
end
|
||||||
|
@ -64,24 +64,20 @@ module RestClient
|
||||||
transmit uri, net_http_request_class(method).new(uri.request_uri, processed_headers), payload, & block
|
transmit uri, net_http_request_class(method).new(uri.request_uri, processed_headers), payload, & block
|
||||||
end
|
end
|
||||||
|
|
||||||
# Extract the query parameters for get request and append them to the url
|
# Extract the query parameters and append them to the url
|
||||||
def process_get_params url, headers
|
def process_url_params url, headers
|
||||||
if [:get, :head, :delete].include? method
|
url_params = {}
|
||||||
get_params = {}
|
headers.delete_if do |key, value|
|
||||||
headers.delete_if do |key, value|
|
if 'params' == key.to_s.downcase && value.is_a?(Hash)
|
||||||
if 'params' == key.to_s.downcase && value.is_a?(Hash)
|
url_params .merge! value
|
||||||
get_params.merge! value
|
true
|
||||||
true
|
|
||||||
else
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
unless get_params.empty?
|
|
||||||
query_string = get_params.collect { |k, v| "#{k.to_s}=#{CGI::escape(v.to_s)}" }.join('&')
|
|
||||||
url + "?#{query_string}"
|
|
||||||
else
|
else
|
||||||
url
|
false
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
unless url_params .empty?
|
||||||
|
query_string = url_params .collect { |k, v| "#{k.to_s}=#{CGI::escape(v.to_s)}" }.join('&')
|
||||||
|
url + "?#{query_string}"
|
||||||
else
|
else
|
||||||
url
|
url
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue