Class: Aliyun::OSS::Client
- Inherits:
-
Object
- Object
- Aliyun::OSS::Client
- Includes:
- Logging
- Defined in:
- lib/aliyun/oss/client.rb
Overview
OSS服务的客户端,用于获取bucket列表,创建/删除bucket。Object相关的操作请使用Bucket。
Constant Summary
Constants included from Logging
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.
Methods included from Logging
#logger, set_log_file, set_log_level
Constructor Details
#initialize(opts) ⇒ Client
构造OSS client,用于操作buckets。
39 40 41 42 43 44 |
# File 'lib/aliyun/oss/client.rb', line 39 def initialize(opts) fail ClientError, "Endpoint must be provided" unless opts[:endpoint] @config = Config.new(opts) @protocol = Protocol.new(@config) end |
Instance Method Details
#bucket_exists?(name) ⇒ Boolean Also known as: bucket_exist?
判断一个bucket是否存在
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/aliyun/oss/client.rb', line 76 def bucket_exists?(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
62 63 64 |
# File 'lib/aliyun/oss/client.rb', line 62 def create_bucket(name, opts = {}) @protocol.create_bucket(name, opts) end |
#delete_bucket(name) ⇒ Object
Note:
如果要删除的Bucket不为空(包含有object),则删除会失败
删除一个bucket
69 70 71 |
# File 'lib/aliyun/oss/client.rb', line 69 def delete_bucket(name) @protocol.delete_bucket(name) end |
#get_bucket(name) ⇒ Bucket
获取一个Bucket对象,用于操作bucket中的objects。
94 95 96 |
# File 'lib/aliyun/oss/client.rb', line 94 def get_bucket(name) Bucket.new({:name => name}, @protocol) end |
#list_buckets(opts = {}) ⇒ Enumerator<Bucket>
列出当前所有的bucket
50 51 52 53 54 55 56 |
# File 'lib/aliyun/oss/client.rb', line 50 def list_buckets(opts = {}) if @config.cname fail ClientError, "Cannot list buckets for a CNAME endpoint." end Iterator::Buckets.new(@protocol, opts).to_enum end |