happening 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -33,17 +33,17 @@ module Happening
33
33
  Happening::S3::Request.new(:get, url, request_options).execute
34
34
  end
35
35
 
36
- def put(data, request_options = {})
36
+ def put(data, request_options = {}, &blk)
37
37
  permissions = options[:permissions] != 'private' ? {'x-amz-acl' => options[:permissions] } : {}
38
38
  headers = needs_to_sign? ? aws.sign("PUT", path, permissions.update({'url' => path})) : {}
39
-
39
+ request_options[:on_success] = blk if blk
40
40
  request_options.update(:headers => headers, :data => data)
41
41
  Happening::S3::Request.new(:put, url, request_options).execute
42
42
  end
43
43
 
44
- def delete(request_options = {})
44
+ def delete(request_options = {}, &blk)
45
45
  headers = needs_to_sign? ? aws.sign("DELETE", path, {'url' => path}) : {}
46
-
46
+ request_options[:on_success] = blk if blk
47
47
  request_options.update(:headers => headers)
48
48
  Happening::S3::Request.new(:delete, url, request_options).execute
49
49
  end
data/test/s3/item_test.rb CHANGED
@@ -176,6 +176,34 @@ class ItemTest < Test::Unit::TestCase
176
176
  end
177
177
  end
178
178
 
179
+ should "support direct blocks" do
180
+ EventMachine::MockHttpRequest.register('https://bucket.s3.amazonaws.com:443/the-key', :delete, {
181
+ "Authorization"=>"AWS abc:nvkrlq4wor1qbFXZh6rHnAbiRjk=",
182
+ 'date' => @time,
183
+ 'url' => "/bucket/the-key"}, fake_response("data-here"))
184
+
185
+ called = false
186
+ data = nil
187
+ @item = Happening::S3::Item.new('bucket', 'the-key', :aws_access_key_id => 'abc', :aws_secret_access_key => '123')
188
+ run_in_em_loop do
189
+ @item.delete do |http|
190
+ called = true
191
+ data = http.response
192
+ end
193
+
194
+ EM.add_timer(1) {
195
+ assert called
196
+ assert_equal "data-here\n", data
197
+ EM.stop_event_loop
198
+ assert_equal 1, EventMachine::MockHttpRequest.count('https://bucket.s3.amazonaws.com:443/the-key', :delete, {
199
+ "Authorization"=>"AWS abc:nvkrlq4wor1qbFXZh6rHnAbiRjk=",
200
+ 'date' => @time,
201
+ 'url' => "/bucket/the-key"})
202
+ }
203
+
204
+ end
205
+ end
206
+
179
207
  should "handle re-direct" do
180
208
  EventMachine::MockHttpRequest.register('https://bucket.s3.amazonaws.com:443/the-key', :delete, {
181
209
  "Authorization"=>"AWS abc:nvkrlq4wor1qbFXZh6rHnAbiRjk=",
@@ -250,6 +278,34 @@ class ItemTest < Test::Unit::TestCase
250
278
  end
251
279
  end
252
280
 
281
+ should "support direct blocks" do
282
+ EventMachine::MockHttpRequest.register('https://bucket.s3.amazonaws.com:443/the-key', :put, {
283
+ "Authorization"=>"AWS abc:lZMKxGDKcQ1PH8yjbpyN7o2sPWg=",
284
+ 'date' => @time,
285
+ 'url' => "/bucket/the-key"}, fake_response("data-here"))
286
+
287
+ called = false
288
+ data = nil
289
+ @item = Happening::S3::Item.new('bucket', 'the-key', :aws_access_key_id => 'abc', :aws_secret_access_key => '123')
290
+ run_in_em_loop do
291
+ @item.put('upload me') do |http|
292
+ called = true
293
+ data = http.response
294
+ end
295
+
296
+ EM.add_timer(1) {
297
+ assert called
298
+ assert_equal "data-here\n", data
299
+ EM.stop_event_loop
300
+ assert_equal 1, EventMachine::MockHttpRequest.count('https://bucket.s3.amazonaws.com:443/the-key', :put, {
301
+ "Authorization"=>"AWS abc:lZMKxGDKcQ1PH8yjbpyN7o2sPWg=",
302
+ 'date' => @time,
303
+ 'url' => "/bucket/the-key"})
304
+ }
305
+
306
+ end
307
+ end
308
+
253
309
  should "set the desired permissions" do
254
310
  EventMachine::MockHttpRequest.register('https://bucket.s3.amazonaws.com:443/the-key', :put, {
255
311
  "Authorization"=>"AWS abc:cqkfX+nC7WIkYD+yWaUFuoRuePA=",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: happening
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Weiss
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-26 00:00:00 +01:00
12
+ date: 2010-02-27 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency