chrisjpowers-patron 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/patron/request.rb +29 -1
- metadata +1 -1
data/lib/patron/request.rb
CHANGED
@@ -40,9 +40,22 @@ module Patron
|
|
40
40
|
@max_redirects = -1
|
41
41
|
end
|
42
42
|
|
43
|
-
attr_accessor :url, :username, :password, :
|
43
|
+
attr_accessor :url, :username, :password, :file_name, :proxy
|
44
44
|
attr_reader :action, :timeout, :connect_timeout, :max_redirects, :headers
|
45
45
|
|
46
|
+
def upload_data=(data)
|
47
|
+
@upload_data = case data
|
48
|
+
when Hash:
|
49
|
+
hash_to_string(data)
|
50
|
+
else
|
51
|
+
data
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def upload_data
|
56
|
+
@upload_data
|
57
|
+
end
|
58
|
+
|
46
59
|
def action=(new_action)
|
47
60
|
if !VALID_ACTIONS.include?(new_action)
|
48
61
|
raise ArgumentError, "Action must be one of #{VALID_ACTIONS.join(', ')}"
|
@@ -92,5 +105,20 @@ module Patron
|
|
92
105
|
"#{username}:#{password}"
|
93
106
|
end
|
94
107
|
|
108
|
+
private
|
109
|
+
|
110
|
+
# serialize hash for Rails-style params
|
111
|
+
def hash_to_string(hash)
|
112
|
+
pairs = []
|
113
|
+
recursive = Proc.new do |h, prefix|
|
114
|
+
h.each_pair do |k,v|
|
115
|
+
key = prefix == '' ? k : "#{prefix}[#{k}]"
|
116
|
+
v.is_a?(Hash) ? recursive.call(v, key) : pairs << "#{key}=#{v}"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
recursive.call(hash, '')
|
120
|
+
return pairs.join('&')
|
121
|
+
end
|
122
|
+
|
95
123
|
end
|
96
124
|
end
|