class COS::Client

Attributes

api[R]
config[R]

Public Class Methods

new(options = {}) click to toggle source

初始化

@see COS::Config

# @example

COS::Client.new(app_id: '', secret_id: '', secret_key: '')

@param options [Hash] 客户端配置

@return [COS::Client]

@raise [AttrError] 如果缺少参数会抛出参数错误异常

# File lib/cos/client.rb, line 21
def initialize(options = {})
  @config = Config.new(options)
  @api    = API.new(@config)
  @cache_buckets = {}
end

Public Instance Methods

bucket(bucket_name = nil) click to toggle source

指定bucket 初始化Bucket类

@note SDK会自动获取bucket的信息,包括读取权限等并进行缓存

如需在后台修改了bucket信息请重新初始化Client

@param bucket_name [String] bucket名称

如果在初始化时的配置中设置了default_bucket则该字段可以为空,会获取默认的bucket

@return [COS::Bucket]

@raise [ClientError] 未指定bucket @raise [ServerError] bucket不存在

# File lib/cos/client.rb, line 48
def bucket(bucket_name = nil)
  unless @cache_buckets[bucket_name]
    # 缓存bucket对象
    @cache_buckets[bucket_name] = Bucket.new(self, bucket_name)
  end
  @cache_buckets[bucket_name]
end
signature() click to toggle source

获取鉴权签名方法

@see COS::Signature

@return [COS::Signature]

# File lib/cos/client.rb, line 32
def signature
  api.http.signature
end