fog--fog/lib/fog/aws/requests/s3/put_bucket.rb

66 lines
1.8 KiB
Ruby
Raw Normal View History

2010-03-13 21:37:24 +00:00
module Fog
module AWS
module S3
class Real
# Create an S3 bucket
#
# ==== Parameters
# * bucket_name<~String> - name of bucket to create
# * options<~Hash> - config arguments for bucket. Defaults to {}.
# * :location_constraint<~Symbol> - sets the location for the bucket
#
# ==== Returns
# * response<~Excon::Response>:
# * status<~Integer> - 200
def put_bucket(bucket_name, options = {})
if options['LocationConstraint']
data =
2010-03-13 21:37:24 +00:00
<<-DATA
<CreateBucketConfiguration>
<LocationConstraint>#{options['LocationConstraint']}</LocationConstraint>
</CreateBucketConfiguration>
DATA
else
data = nil
end
request({
:expects => 200,
:body => data,
:headers => {},
:idempotent => true,
:host => "#{bucket_name}.#{@host}",
:method => 'PUT'
})
end
end
2010-03-13 21:37:24 +00:00
class Mock
def put_bucket(bucket_name, options = {})
2009-11-20 19:08:08 +00:00
response = Excon::Response.new
response.status = 200
2009-08-09 05:40:42 +00:00
bucket = {
:objects => {},
'Name' => bucket_name,
'CreationDate' => Time.now,
2009-11-21 18:28:18 +00:00
'Owner' => { 'DisplayName' => 'owner', 'ID' => 'some_id'},
'Payer' => 'BucketOwner'
}
2009-08-09 05:40:42 +00:00
if options['LocationConstraint']
bucket['LocationConstraint'] = options['LocationConstraint']
else
bucket['LocationConstraint'] = ''
end
2010-03-13 21:37:24 +00:00
unless @data[:buckets][bucket_name]
@data[:buckets][bucket_name] = bucket
2009-09-08 18:54:38 +00:00
end
response
end
end
end
end
2010-03-13 21:37:24 +00:00
end