From 1060baed797e2d6a4cc30a0a7068091bf78eeb48 Mon Sep 17 00:00:00 2001 From: Julien Kirch Date: Sun, 26 Jun 2011 17:31:07 +0200 Subject: [PATCH] enable url parameters for all actions. Closes #53 --- history.md | 1 + lib/restclient/request.rb | 30 +++++++++++++----------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/history.md b/history.md index 6ab79ad..96c0439 100644 --- a/history.md +++ b/history.md @@ -1,6 +1,7 @@ # 1.6.5 - 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 diff --git a/lib/restclient/request.rb b/lib/restclient/request.rb index e1345ac..895e4f5 100644 --- a/lib/restclient/request.rb +++ b/lib/restclient/request.rb @@ -37,7 +37,7 @@ module RestClient @method = args[:method] or raise ArgumentError, "must pass :method" @headers = args[:headers] || {} if args[:url] - @url = process_get_params(args[:url], headers) + @url = process_url_params(args[:url], headers) else raise ArgumentError, "must pass :url" end @@ -64,24 +64,20 @@ module RestClient transmit uri, net_http_request_class(method).new(uri.request_uri, processed_headers), payload, & block end - # Extract the query parameters for get request and append them to the url - def process_get_params url, headers - if [:get, :head, :delete].include? method - get_params = {} - headers.delete_if do |key, value| - if 'params' == key.to_s.downcase && value.is_a?(Hash) - get_params.merge! value - 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}" + # Extract the query parameters and append them to the url + def process_url_params url, headers + url_params = {} + headers.delete_if do |key, value| + if 'params' == key.to_s.downcase && value.is_a?(Hash) + url_params .merge! value + true else - url + false 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 url end