Class: QcloudCos::ObjectManager

Inherits:
Object
  • Object
show all
Defined in:
lib/qcloud_cos/object_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket: nil, region: nil, access_id: nil, access_key: nil, token: nil) ⇒ ObjectManager

Returns a new instance of ObjectManager.



5
6
7
8
9
10
11
12
# File 'lib/qcloud_cos/object_manager.rb', line 5

def initialize(bucket: nil, region: nil, access_id: nil, access_key: nil, token: nil)
  @bucket = bucket
  @region = region
  @access_id = access_id
  @access_key = access_key
  @token = token
  @http = QcloudCos::Http.new(access_id, access_key, token: token)
end

Instance Attribute Details

#access_idObject

Returns the value of attribute access_id.



4
5
6
# File 'lib/qcloud_cos/object_manager.rb', line 4

def access_id
  @access_id
end

#access_keyObject

Returns the value of attribute access_key.



4
5
6
# File 'lib/qcloud_cos/object_manager.rb', line 4

def access_key
  @access_key
end

#bucketObject

Returns the value of attribute bucket.



4
5
6
# File 'lib/qcloud_cos/object_manager.rb', line 4

def bucket
  @bucket
end

#httpObject

Returns the value of attribute http.



4
5
6
# File 'lib/qcloud_cos/object_manager.rb', line 4

def http
  @http
end

#regionObject

Returns the value of attribute region.



4
5
6
# File 'lib/qcloud_cos/object_manager.rb', line 4

def region
  @region
end

#tokenObject

Returns the value of attribute token.



4
5
6
# File 'lib/qcloud_cos/object_manager.rb', line 4

def token
  @token
end

Instance Method Details

#compute_url(path) ⇒ Object



28
29
30
# File 'lib/qcloud_cos/object_manager.rb', line 28

def compute_url(path)
  URI.join("https://#{bucket}.cos.#{region}.myqcloud.com", path).to_s
end

#copy_object(path, copy_source) ⇒ Object



19
20
21
22
# File 'lib/qcloud_cos/object_manager.rb', line 19

def copy_object(path, copy_source)
  body = http.put(compute_url(path), nil, 'x-cos-copy-source' => copy_source).body
  ActiveSupport::HashWithIndifferentAccess.new(ActiveSupport::XmlMini.parse(body))
end

#delete_object(path) ⇒ Object



24
25
26
# File 'lib/qcloud_cos/object_manager.rb', line 24

def delete_object(path)
  http.delete(compute_url(path))
end

#put_object(path, file_or_bin, headers = {}) ⇒ Object



14
15
16
17
# File 'lib/qcloud_cos/object_manager.rb', line 14

def put_object(path, file_or_bin, headers = {})
  data = file_or_bin.respond_to?(:read) ? IO.binread(file_or_bin) : file_or_bin
  http.put(compute_url(path), data, headers)
end