Class: COS::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/cos/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ COS::Client

初始化

# @example

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

Raises:

  • (AttrError)

    如果缺少参数会抛出参数错误异常

See Also:


21
22
23
24
25
# File 'lib/cos/client.rb', line 21

def initialize(options = {})
  @config = Config.new(options)
  @api    = API.new(@config)
  @cache_buckets = {}
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api


7
8
9
# File 'lib/cos/client.rb', line 7

def api
  @api
end

#configObject (readonly)

Returns the value of attribute config


7
8
9
# File 'lib/cos/client.rb', line 7

def config
  @config
end

Instance Method Details

#bucket(bucket_name = nil) ⇒ COS::Bucket

Note:

SDK会自动获取bucket的信息,包括读取权限等并进行缓存 如需在后台修改了bucket信息请重新初始化Client

指定bucket 初始化Bucket类

Raises:


48
49
50
51
52
53
54
# 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

#signatureCOS::Signature

获取鉴权签名方法

See Also:


32
33
34
# File 'lib/cos/client.rb', line 32

def signature
  api.http.signature
end