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: '')

Parameters:

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

    客户端配置

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类

Parameters:

  • bucket_name (String) (defaults to: nil)

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

Returns:

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

获取鉴权签名方法

Returns:

See Also:


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

def signature
  api.http.signature
end