class QcloudCos::ObjectManager

Attributes

access_id[RW]
access_key[RW]
bucket[RW]
http[RW]
region[RW]
token[RW]

Public Class Methods

new(bucket: nil, region: nil, access_id: nil, access_key: nil, token: nil) click to toggle source
# 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

Public Instance Methods

compute_url(path) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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 = {}) click to toggle source
# 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