Class: Backup::CloudIO::QiNiu

Inherits:
Base
  • Object
show all
Defined in:
lib/backup/cloud_io/qi_niu.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Attributes inherited from Base

#max_retries, #retry_waitsec

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ QiNiu

Returns a new instance of QiNiu.



33
34
35
36
37
38
39
40
41
42
# File 'lib/backup/cloud_io/qi_niu.rb', line 33

def initialize(options = {})
  super

  @access_key = options[:access_key]
  @secret_key = options[:secret_key]
  @bucket     = options[:bucket]
  @expires_in = options[:expires_in] || 31536000 # 3600*24*365

  establish_connection!
end

Instance Attribute Details

#access_keyObject (readonly)

Returns the value of attribute access_key.



31
32
33
# File 'lib/backup/cloud_io/qi_niu.rb', line 31

def access_key
  @access_key
end

#bucketObject (readonly)

Returns the value of attribute bucket.



31
32
33
# File 'lib/backup/cloud_io/qi_niu.rb', line 31

def bucket
  @bucket
end

#expires_inObject (readonly)

Returns the value of attribute expires_in.



31
32
33
# File 'lib/backup/cloud_io/qi_niu.rb', line 31

def expires_in
  @expires_in
end

#secret_keyObject (readonly)

Returns the value of attribute secret_key.



31
32
33
# File 'lib/backup/cloud_io/qi_niu.rb', line 31

def secret_key
  @secret_key
end

#uptokenObject (readonly)

Returns the value of attribute uptoken.



31
32
33
# File 'lib/backup/cloud_io/qi_niu.rb', line 31

def uptoken
  @uptoken
end

Instance Method Details

#delete(objects) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/backup/cloud_io/qi_niu.rb', line 59

def delete(objects)
  Logger.info "\s\sDeleting from Qiniu..."
  with_retries("DELETE objects") do
    objects.each do |object|
      wrap_results Qiniu::Storage.delete(bucket, object['key']),
        success_info: "\s\sDelete #{object['key']} success",
        fail_info: "Delete #{object['key']} from Qiniu failed!"
    end
  end
end

#objects(remote_path) ⇒ Object



54
55
56
57
# File 'lib/backup/cloud_io/qi_niu.rb', line 54

def objects(remote_path)
  _, result, _ = Qiniu::Storage.list(bucket, remote_path)
  result['items']
end

#upload(src, dest) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/backup/cloud_io/qi_niu.rb', line 44

def upload(src, dest)
  Logger.info "\s\sUploading #{src} to Qiniu..."
  put_policy = Qiniu::Auth::PutPolicy.new(bucket, nil, expires_in)
  with_retries("Upload with put policy") do
    wrap_results Qiniu::Storage.upload_with_put_policy(put_policy, src, dest),
      success_info: "\s\sUpload to Qiniu success",
      fail_info: 'Upload to Qiniu failed!'
  end
end