Sha256: 5799390b415689df37b791c08e9a1afe1b4d0ce77cd00ecc4853249a3b34d886

Contents?: true

Size: 1.91 KB

Versions: 12

Compression:

Stored size: 1.91 KB

Contents

module Fog
  module Google
    class Storage
      class Real

        # Create an Google Storage 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 =
<<-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

      class Mock

        def put_bucket(bucket_name, options = {})
          response = Excon::Response.new
          response.status = 200
          bucket = {
            :objects        => {},
            'Name'          => bucket_name,
            'CreationDate'  => Time.now,
            'Owner'         => { 'DisplayName' => 'owner', 'ID' => 'some_id'},
            'Payer'         => 'BucketOwner'
          }
          if options['LocationConstraint']
            bucket['LocationConstraint'] = options['LocationConstraint']
          else
            bucket['LocationConstraint'] = ''
          end
          if @data[:buckets][bucket_name].nil?
            @data[:buckets][bucket_name] = bucket
          else
            response.status = 409
            raise(Excon::Errors.status_error({:expects => 200}, response))
          end
          response
        end

      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
fog-0.3.13 lib/fog/google/requests/storage/put_bucket.rb
fog-0.3.12 lib/fog/google/requests/storage/put_bucket.rb
fog-0.3.11 lib/fog/google/requests/storage/put_bucket.rb
fog-0.3.10 lib/fog/google/requests/storage/put_bucket.rb
fog-0.3.9 lib/fog/google/requests/storage/put_bucket.rb
fog-0.3.8 lib/fog/google/requests/storage/put_bucket.rb
fog-0.3.7 lib/fog/google/requests/storage/put_bucket.rb
fog-0.3.6 lib/fog/google/requests/storage/put_bucket.rb
fog-0.3.5 lib/fog/google/requests/storage/put_bucket.rb
fog-0.3.4 lib/fog/google/requests/storage/put_bucket.rb
fog-0.3.3 lib/fog/google/requests/storage/put_bucket.rb
fog-0.3.2 lib/fog/google/requests/storage/put_bucket.rb