Skip to content

Commit

Permalink
Merge pull request #400 from grddev/support_s3_get_torrent
Browse files Browse the repository at this point in the history
Support S3 GET Object torrent
  • Loading branch information
trevorrowe committed Nov 5, 2013
2 parents 8bfc473 + 0f7c40a commit 5faa4b9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/aws/s3/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,20 @@ def self.object_method(method_name, verb, *args, &block)

end

# Gets the torrent for a key.
# @overload get_object_torrent(options = {})
# @param [Hash] options
# @option options [required,String] :bucket_name
# @option options [required,String] :key
# @return [Core::Response]
#
object_method(:get_object_torrent, :get, 'torrent') do
process_response do |resp|
extract_object_headers(resp)
resp.data[:data] = resp.http_response.body
end
end

# @overload head_object(options = {})
# @param [Hash] options
# @option options [required,String] :bucket_name
Expand Down
41 changes: 41 additions & 0 deletions spec/aws/s3/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,47 @@ def should_determine_content_length_for data, length

end

context '#get_object_torrent' do

let(:method) { :get_object_torrent }

let(:opts) { { :bucket_name => 'foo', :key => 'some/key' } }

it_should_behave_like "requires bucket_name"

it_should_behave_like "an s3 http request", 'GET'

it_should_behave_like "returns server_side_encryption"

context 'response' do

let(:body) { "FOO DATA" }

it 'should return the bencoded response body from the data method' do
http_handler.stub(:handle) do |req, resp|
resp.body = body
end
client.get_object(opts).data[:data].should == "FOO DATA"
end

it 'should read the bencoded response body on success' do
got_handle = nil
got_resp = nil
http_handler.stub(:handle_async) do |req, resp, handle|
got_resp = resp
got_handle = handle
end
r = client.get_object(opts.merge(:async => true))
got_resp.body = body
got_resp.status = 200
got_handle.signal_success
r.data[:data].should == "FOO DATA"
end

end

end

context '#head_object' do

let(:method) { :head_object }
Expand Down

0 comments on commit 5faa4b9

Please sign in to comment.