Class: Backup::CloudIO::QiNiu
- Defined in:
- lib/backup/cloud_io/qi_niu.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#access_key ⇒ Object
readonly
Returns the value of attribute access_key.
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#expires_in ⇒ Object
readonly
Returns the value of attribute expires_in.
-
#secret_key ⇒ Object
readonly
Returns the value of attribute secret_key.
-
#uptoken ⇒ Object
readonly
Returns the value of attribute uptoken.
Attributes inherited from Base
Instance Method Summary collapse
- #delete(objects) ⇒ Object
-
#initialize(options = {}) ⇒ QiNiu
constructor
A new instance of QiNiu.
- #objects(remote_path) ⇒ Object
- #upload(src, dest) ⇒ Object
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( = {}) super @access_key = [:access_key] @secret_key = [:secret_key] @bucket = [:bucket] @expires_in = [:expires_in] || 31536000 # 3600*24*365 establish_connection! end |
Instance Attribute Details
#access_key ⇒ Object (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 |
#bucket ⇒ Object (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_in ⇒ Object (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_key ⇒ Object (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 |
#uptoken ⇒ Object (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 |