lib/patron/request.rb in patron-0.4.11 vs lib/patron/request.rb in patron-0.4.12

- old
+ new

@@ -21,11 +21,11 @@ ## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ## THE SOFTWARE. ## ## ------------------------------------------------------------------- -require 'cgi' +require 'patron/util' module Patron # Represents the information necessary for an HTTP request. # This is basically a data object with validation. Not all fields will be @@ -69,11 +69,11 @@ end def upload_data=(data) @upload_data = case data when Hash - self.multipart ? data : hash_to_string(data) + self.multipart ? data : Util.build_query_string_from_hash(data, @action == :post) else data end end @@ -136,22 +136,7 @@ def credentials return nil if username.nil? || password.nil? "#{username}:#{password}" end - private - - # serialize hash for Rails-style params - def hash_to_string(hash) - pairs = [] - recursive = Proc.new do |h, prefix| - h.each_pair do |k,v| - key = prefix == '' ? k : "#{prefix}[#{k}]" - @action == :post ? v = CGI::escape(v.to_s) : v - v.is_a?(Hash) ? recursive.call(v, key) : pairs << "#{key}=#{v}" - end - end - recursive.call(hash, '') - return pairs.join('&') - end end end