happening
happening copied to clipboard
webmock for tests/non-blocking put for large files/default settings/callback ease
I stumbled upon the missing of MockHttpRequest for version 1.0.0 of em-http-request. That's why I changed the tests to use WebMock, which cleaned up the tests a bit and made them green again.
EDIT: Additional changes:
-
S3::Request#execute
returnsS3::Request
object for later callback chaining (importantEM::HttpRequest
methods delegated) - set defaults (access_key_id, secret_access_key, bucket) with
Happening::AWS.set_defaults({ ... })
- added
on_retry
callback - simplified adding callbacks from blocks
Added some more.
Now you can put like this:
@item = Happening::S3::Item.new('mybucket', 'bla.mp4')
@item.put(:file => '/path/to/local/bla.mp4')
This will pass the :file option directly to em-http-request, which will upload the file chunkwise with the magnificent EventMachine::FileStreamer. No more blocking when using File.read
. Yay!
I changed the execute
method to return the Happening::S3::Request
object, for later callback methods.
The EM::HttpRequest
methods/callbacks #stream
and #headers
are delegated.
It makes more sense, because we create a request with all the put/get/head/delete methods. The response is an accessor of this request.
Next step would be to provide something like this:
@item = Happening::S3::Item.new('bucket', 'object_id')
upload = @item.put(:file => '/path/to/file')
upload.on_success do
puts "success!"
end
upload.on_error do
puts "error!"
end
Or even simpler with:
upload = Happening::S3::Item.new('bucket', 'object_id').put(:file => '/path/to/file')
upload.on_success do
puts "success!"
end
upload.on_error do
puts "error!"
end
You can now set defaults for all items:
Happening::AWS.set_defaults(:aws_access_key_id => 'key',
:aws_secret_access_key => 'secret',
:bucket => 'bucket')
# the bucket default removes the need for a bucket, when instantiating a new item:
upload = Happening::S3::Item.new('object-id').put(:file => '/my/large/file')
Taking the example from before, you can specify callbacks via blocks, no procs for options anymore.
Happening::AWS.set_defaults(:aws_access_key_id => 'key',
:aws_secret_access_key => 'secret',
:bucket => 'bucket')
# the bucket default removes the need for a bucket, when instantiating a new item:
upload = Happening::S3::Item.new('object-id').put(:file => '/my/large/file')
upload.on_success do |uploaded|
puts 'Yay!'
end
upload.on_error do |error|
puts "Error while uploading: #{error.response_header.status}"
end
That's it for now. The last commit added an on_retry
callback.
All tests are passing. I also cleaned up the Readme, fixed some typos and wrong examples.
Hope you gonna pull my changes and publish a new version of your excellent gem.