Module: Aliyun::Oss::Api::Buckets

Included in:
Client
Defined in:
lib/aliyun/oss/api/buckets.rb

Instance Method Summary collapse

Instance Method Details

#bucket_create(name, location = 'oss-cn-hangzhou', acl = 'private') ⇒ Response

Create bucket

Examples:

oss.client.bucket_create('oss-sdk-dev-hangzhou-xxx')

Parameters:

  • name (String)

    Specify bucket name

  • location (String) (defaults to: 'oss-cn-hangzhou')

    Specify the bucket’s data center location, can be one of below: oss-cn-hangzhou,oss-cn-qingdao,oss-cn-beijing,oss-cn-hongkong, oss-cn-shenzhen,oss-cn-shanghai,oss-us-west-1 ,oss-ap-southeast-1

  • acl (String) (defaults to: 'private')

    Specify the bucket’s access. Aliyun::Oss::Api::BucketProperty#bucket_set_acl

Returns:

  • (Response)

Raises:

See Also:



39
40
41
42
43
44
45
46
# File 'lib/aliyun/oss/api/buckets.rb', line 39

def bucket_create(name, location = 'oss-cn-hangzhou', acl = 'private')
  query = { 'acl' => true }
  headers = { 'x-oss-acl' => acl }

  body = XmlGenerator.generate_create_bucket_xml(location)

  http.put('/', query: query, headers: headers, body: body, bucket: name, location: location)
end

#bucket_delete(name) ⇒ Response

Delete bucket

Parameters:

  • name (String)

    bucket name want to delete

Returns:

  • (Response)

Raises:

See Also:



57
58
59
# File 'lib/aliyun/oss/api/buckets.rb', line 57

def bucket_delete(name)
  http.delete('/', bucket: name)
end

#bucket_preflight(object_key, origin, request_method, request_headers = []) ⇒ Response

OPTIONS Object

Parameters:

  • object_key (String)

    the object name want to visit.

  • origin (String)

    the requested source domain, denoting cross-domain request.

  • request_method (String)

    the actual request method will be used.

  • request_headers (Array<String>) (defaults to: [])

    the actual used headers except simple headers will be used.

Returns:

  • (Response)

Raises:

See Also:



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/aliyun/oss/api/buckets.rb', line 73

def bucket_preflight(object_key, origin, request_method, request_headers = [])
  path = object_key ? "/#{object_key}" : '/'

  headers = {
    'Origin' => origin,
    'Access-Control-Request-Method' => request_method
  }

  unless request_headers.empty?
    value = request_headers.join(',')
    headers.merge!('Access-Control-Request-Headers' => value)
  end

  http.options(path, headers: headers, bucket: bucket, key: object_key)
end

#list_buckets(options = {}) ⇒ Response

List buckets

Parameters:

  • options (Hash) (defaults to: {})

    options

Options Hash (options):

  • :prefix (String)

    Filter buckets with prefix

  • :marker (String)

    Bucket name should after marker in alphabetical order

  • :max-keys (Integer) — default: 100

    Limit number of buckets, the maxinum should <= 1000

Returns:

  • (Response)

Raises:

See Also:



17
18
19
20
21
# File 'lib/aliyun/oss/api/buckets.rb', line 17

def list_buckets(options = {})
  Utils.stringify_keys!(options)
  query = Utils.hash_slice(options, 'prefix', 'marker', 'max-keys')
  http.get('/', query: query)
end