Class: Aliyun::OSS::Client
- Inherits:
-
Object
- Object
- Aliyun::OSS::Client
- Defined in:
- lib/aliyun/oss/client.rb
Overview
OSS服务的客户端,用于获取bucket列表,创建/删除bucket。Object相关 的操作请使用Bucket。
Instance Method Summary collapse
-
#bucket_exists?(name) ⇒ Boolean
(also: #bucket_exist?)
判断一个bucket是否存在.
-
#create_bucket(name, opts = {}) ⇒ Object
创建一个bucket.
-
#delete_bucket(name) ⇒ Object
删除一个bucket.
-
#get_bucket(name) ⇒ Bucket
获取一个Bucket对象,用于操作bucket中的objects。.
-
#initialize(opts) ⇒ Client
constructor
构造OSS client,用于操作buckets。.
-
#list_buckets(opts = {}) ⇒ Enumerator<Bucket>
列出当前所有的bucket.
Constructor Details
Instance Method Details
#bucket_exists?(name) ⇒ Boolean Also known as: bucket_exist?
判断一个bucket是否存在
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/aliyun/oss/client.rb', line 88 def bucket_exists?(name) Util.ensure_bucket_name_valid(name) exist = false begin @protocol.get_bucket_acl(name) exist = true rescue ServerError => e raise unless e.http_code == 404 end exist end |
#create_bucket(name, opts = {}) ⇒ Object
创建一个bucket
72 73 74 75 |
# File 'lib/aliyun/oss/client.rb', line 72 def create_bucket(name, opts = {}) Util.ensure_bucket_name_valid(name) @protocol.create_bucket(name, opts) end |
#delete_bucket(name) ⇒ Object
Note:
如果要删除的Bucket不为空(包含有object),则删除会失败
删除一个bucket
80 81 82 83 |
# File 'lib/aliyun/oss/client.rb', line 80 def delete_bucket(name) Util.ensure_bucket_name_valid(name) @protocol.delete_bucket(name) end |
#get_bucket(name) ⇒ Bucket
获取一个Bucket对象,用于操作bucket中的objects。
107 108 109 110 |
# File 'lib/aliyun/oss/client.rb', line 107 def get_bucket(name) Util.ensure_bucket_name_valid(name) Bucket.new({:name => name}, @protocol) end |