markdillon-restclient 1.2 → 1.3
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/restclient.rb +1 -0
- data/lib/restclient/multipart.rb +4 -0
- data/lib/restclient/request.rb +16 -54
- data/restclient.gemspec +1 -1
- metadata +1 -1
data/lib/restclient.rb
CHANGED
data/lib/restclient/multipart.rb
CHANGED
data/lib/restclient/request.rb
CHANGED
@@ -88,6 +88,7 @@ module RestClient
|
|
88
88
|
unless p.is_a?(Hash)
|
89
89
|
p
|
90
90
|
else
|
91
|
+
p = flatten_params(p)
|
91
92
|
if p.delete(:multipart) == true
|
92
93
|
multipart = Multipart.new(p)
|
93
94
|
@headers[:content_type] = %Q{multipart/form-data; boundary="#{multipart.boundary}"}
|
@@ -95,62 +96,25 @@ module RestClient
|
|
95
96
|
else
|
96
97
|
@headers[:content_type] ||= 'application/x-www-form-urlencoded'
|
97
98
|
p.keys.map do |k|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
else
|
102
|
-
value = URI.escape(p[k].to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
103
|
-
"#{key}=#{value}"
|
104
|
-
end
|
105
|
-
end.join("&")
|
99
|
+
value = URI.escape(p[k].to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
100
|
+
"#{k}=#{value}"
|
101
|
+
end.join('&')
|
106
102
|
end
|
107
103
|
end
|
108
104
|
end
|
109
105
|
|
110
|
-
def
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
@stream.write(EOL + b)
|
123
|
-
end
|
124
|
-
@stream.write('--')
|
125
|
-
@stream.write(EOL)
|
126
|
-
@stream.seek(0)
|
127
|
-
end
|
128
|
-
|
129
|
-
def create_regular_field(s, k, v)
|
130
|
-
s.write("Content-Disposition: multipart/form-data; name=\"#{k}\"")
|
131
|
-
s.write(EOL)
|
132
|
-
s.write(EOL)
|
133
|
-
s.write(v)
|
134
|
-
end
|
135
|
-
|
136
|
-
def create_file_field(s, k, v, content_type = nil)
|
137
|
-
content_type ||= `file -b --mime #{v.path}`.gsub(/\n/, '')
|
138
|
-
begin
|
139
|
-
s.write("Content-Disposition: multipart/form-data; name=\"#{k}\"; filename=\"#{v.path}\"#{EOL}")
|
140
|
-
s.write("Content-Type: #{content_type}#{EOL}")
|
141
|
-
s.write(EOL)
|
142
|
-
while data = v.read(8124)
|
143
|
-
s.write(data)
|
144
|
-
end
|
145
|
-
ensure
|
146
|
-
v.close
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
def boundary
|
151
|
-
@boundary ||= rand(1_000_000).to_s
|
152
|
-
end
|
153
|
-
|
106
|
+
def flatten_params(p=nil, parent_key=nil, newp={})
|
107
|
+
p.keys.each do |k|
|
108
|
+
key = parent_key ? "#{parent_key}[#{k}]" : k
|
109
|
+
if p[k].is_a? Hash
|
110
|
+
newp = flatten_params(p[k], key, newp)
|
111
|
+
else
|
112
|
+
newp[key] = p[k]
|
113
|
+
end
|
114
|
+
end
|
115
|
+
return newp
|
116
|
+
end
|
117
|
+
|
154
118
|
def transmit(uri, req, payload)
|
155
119
|
setup_credentials(req)
|
156
120
|
|
@@ -186,8 +150,6 @@ module RestClient
|
|
186
150
|
raise RestClient::ServerBrokeConnection
|
187
151
|
rescue Timeout::Error
|
188
152
|
raise RestClient::RequestTimeout
|
189
|
-
ensure
|
190
|
-
@payload.close
|
191
153
|
end
|
192
154
|
|
193
155
|
def setup_credentials(req)
|
data/restclient.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "restclient"
|
3
|
-
s.version = "1.
|
3
|
+
s.version = "1.3"
|
4
4
|
s.summary = "Simple REST client for Ruby, inspired by microframework syntax for specifying actions."
|
5
5
|
s.description = "A simple REST client for Ruby, inspired by the Sinatra microframework style of specifying actions: get, put, post, delete."
|
6
6
|
s.author = "Adam Wiggins"
|