Class: S3::BucketCreateRequest

Inherits:
Request
  • Object
show all
Defined in:
lib/s3/bucket_create_request.rb

Constant Summary

Constants inherited from Request

Request::AWS_ALGORITHM, Request::AWS_REQUEST, Request::SERVICE, Request::UNSIGNED_PAYLOAD

Instance Method Summary collapse

Methods inherited from Request

#initialize

Constructor Details

This class inherits a constructor from S3::Request

Instance Method Details

#submit(options = nil, bucket:, **kwargs) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/s3/bucket_create_request.rb', line 3

def submit( options = nil, bucket:, **kwargs )
  options = merge_options( options, kwargs, BucketCreateOptions )

  headers = {}
  headers[ 'x-amz-acl' ] = options[ :acl ] if options[ :acl ]

  body = nil
  location = options[ :region ] || @region

  if location && location != 'us-east-1'
    body = <<~XML
      <?xml version="1.0" encoding="UTF-8"?>
      <CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
        <LocationConstraint>#{ location }</LocationConstraint>
      </CreateBucketConfiguration>
    XML
  end

  response = put( "/#{ bucket }", body: body, headers: headers )

  build_result( response, TrueClass ) do
    true
  end
end