backup-baidu 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/backup-baidu.gemspec +1 -1
- data/lib/backup/storage/baidu.rb +7 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3edb7181f9fdbd1ca5cb769d663450a8df421500
|
4
|
+
data.tar.gz: af5fb235f2d09b72904c3d8c5372dc6ba381da72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8bc60e6cc1e9edd17c3ba3ff088d54a190d11fc8831150bfca276913e644285e3eb2851b5a46b18486d7a98833bb6a74edc813e23c07b619d48879655f16b29
|
7
|
+
data.tar.gz: fe082f9619f6db1c5f37819e60fc8460ce043c9890483824f4b639fbb1a5541324d699d49b7d522650ba766bc2be514deccc9b2c94698df60b50752e0955219a
|
data/backup-baidu.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "backup-baidu"
|
7
|
-
spec.version = "0.
|
7
|
+
spec.version = "0.3.0"
|
8
8
|
spec.authors = ["DylanDeng", "George Lee"]
|
9
9
|
spec.email = ["dylan@beansmile.com", "mclee@foolme.net"]
|
10
10
|
spec.description = %q{pan.baidu.com Storage support for Backup}
|
data/lib/backup/storage/baidu.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
module Backup
|
2
2
|
module Storage
|
3
3
|
class Baidu < Base
|
4
|
-
attr_accessor :api_key, :api_secret, :path
|
4
|
+
attr_accessor :api_key, :api_secret, :path, :cache_path
|
5
5
|
|
6
6
|
def initialize(model, storage_id = nil, &block)
|
7
7
|
super(model, storage_id)
|
8
8
|
|
9
9
|
@path ||= 'backups'
|
10
|
+
@cache_path ||= '.cache'
|
10
11
|
|
11
12
|
instance_eval(&block) if block_given?
|
12
13
|
end
|
@@ -37,7 +38,7 @@ module Backup
|
|
37
38
|
|
38
39
|
def save_session(token)
|
39
40
|
@access_token = token
|
40
|
-
FileUtils.mkdir_p(
|
41
|
+
FileUtils.mkdir_p(self.cache_path) unless File.directory?(self.cache_path)
|
41
42
|
File.open(cached_file,"w") do |f|
|
42
43
|
f.puts @access_token.to_hash.to_json
|
43
44
|
end
|
@@ -49,9 +50,9 @@ module Backup
|
|
49
50
|
stored_data = File.open(cached_file).read
|
50
51
|
@session = OAuth2::AccessToken.from_hash(@connection.oauth_client, JSON.parse(stored_data))
|
51
52
|
if @session.expired?
|
52
|
-
Logger.info "Access Token
|
53
|
+
Logger.info "Access Token expired, refreshing a new token..."
|
53
54
|
new_token = @session.refresh!
|
54
|
-
Logger.info "Refresh
|
55
|
+
Logger.info "Refresh successful. #{new_token.token}"
|
55
56
|
save_session(new_token)
|
56
57
|
end
|
57
58
|
end
|
@@ -59,7 +60,7 @@ module Backup
|
|
59
60
|
end
|
60
61
|
|
61
62
|
def cached_file
|
62
|
-
File.join(
|
63
|
+
File.join(self.cache_path, "baidu-" + self.api_key + "-" + self.api_secret)
|
63
64
|
end
|
64
65
|
|
65
66
|
def transfer!
|
@@ -74,7 +75,7 @@ module Backup
|
|
74
75
|
|
75
76
|
def remove!(package)
|
76
77
|
remote_path = remote_path_for(package)
|
77
|
-
Logger.info "
|
78
|
+
Logger.info "Removing '#{remote_path}' from Baidu..."
|
78
79
|
connection.delete(remote_path)
|
79
80
|
end
|
80
81
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backup-baidu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DylanDeng
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-04-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
version: '0'
|
121
121
|
requirements: []
|
122
122
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.2.
|
123
|
+
rubygems_version: 2.2.2
|
124
124
|
signing_key:
|
125
125
|
specification_version: 4
|
126
126
|
summary: pan.baidu.com Storage support for Backup
|