rested 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rested/base.rb +3 -1
- data/lib/rested/debug.rb +1 -1
- data/lib/rested/entity.rb +41 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/lib/rested/base.rb
CHANGED
@@ -13,7 +13,9 @@ module Rested
|
|
13
13
|
if self.user and self.pass then
|
14
14
|
@client.set_auth(self.base_url, self.user, self.pass)
|
15
15
|
end
|
16
|
-
|
16
|
+
if not Rested.debug.nil?
|
17
|
+
@client.debug_dev = (Rested.debug.respond_to?("<<") ? Rested.debug : STDOUT)
|
18
|
+
end
|
17
19
|
@client
|
18
20
|
end
|
19
21
|
|
data/lib/rested/debug.rb
CHANGED
data/lib/rested/entity.rb
CHANGED
@@ -211,15 +211,27 @@ module Rested
|
|
211
211
|
self.class.before_filters.each do |f|
|
212
212
|
f.call(self)
|
213
213
|
end
|
214
|
+
|
214
215
|
uri = self.endpoint
|
215
216
|
uri += "/#{self.id_val}" unless new?
|
217
|
+
|
216
218
|
params = to_h() if not params
|
217
219
|
params.delete(self.id_field) if new?
|
218
|
-
|
220
|
+
|
221
|
+
if not self.files.empty?
|
219
222
|
params.merge!(self.files)
|
220
223
|
@files = {}
|
221
224
|
end
|
222
|
-
|
225
|
+
params = preserve_filenames(params)
|
226
|
+
|
227
|
+
begin
|
228
|
+
ret = self.post(uri, params)
|
229
|
+
cleanup_temp_files(params)
|
230
|
+
rescue => ex
|
231
|
+
cleanup_temp_files(params)
|
232
|
+
raise ex
|
233
|
+
end
|
234
|
+
|
223
235
|
if new? then
|
224
236
|
self.id_val = self.class.new(ret.values.first).id_val
|
225
237
|
end
|
@@ -243,5 +255,32 @@ module Rested
|
|
243
255
|
def delimited_fields
|
244
256
|
@delimited_fields ||= self.class.delimited_fields
|
245
257
|
end
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
private
|
262
|
+
|
263
|
+
# simple trick to force httpclient to pass the real filename
|
264
|
+
# we simply rename our temp file to its original in a unique directory
|
265
|
+
def preserve_filenames(params)
|
266
|
+
params.each { |k,v|
|
267
|
+
if v.kind_of? Tempfile and v.respond_to? "original_filename" then
|
268
|
+
FileUtils.mkdir_p(v.path + "-origfile")
|
269
|
+
FileUtils.mv(v.path, v.path + "-origfile/" + v.original_filename)
|
270
|
+
params[k] = File.new(v.path + "-origfile/" + v.original_filename)
|
271
|
+
end
|
272
|
+
}
|
273
|
+
params
|
274
|
+
end
|
275
|
+
|
276
|
+
# cleanup temp files created above
|
277
|
+
def cleanup_temp_files(params)
|
278
|
+
params.each { |k,v|
|
279
|
+
if v.kind_of? File
|
280
|
+
FileUtils.rm_rf([v.path, File.dirname(v.path)])
|
281
|
+
end
|
282
|
+
}
|
283
|
+
end
|
284
|
+
|
246
285
|
end
|
247
286
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 1
|
9
|
+
version: 0.3.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Chetan Sarva
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-09-07 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|