baidupan 0.0.5 → 0.0.6
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.
- data/.gitignore +1 -0
- data/.rvmrc +2 -1
- data/lib/baidupan.rb +3 -1
- data/lib/baidupan/cmd/fs_cmd.rb +52 -3
- data/lib/baidupan/config.rb +12 -3
- data/lib/baidupan/core_ext.rb +1 -0
- data/lib/baidupan/core_ext/hash.rb +5 -0
- data/lib/baidupan/fs_cmd.rb +35 -2
- data/lib/baidupan/version.rb +1 -1
- metadata +29 -11
- checksums.yaml +0 -7
data/.gitignore
CHANGED
data/.rvmrc
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
rvm use ruby-2.0.0-p247@common
|
1
|
+
#rvm use ruby-2.0.0-p247@common
|
2
|
+
rvm use ruby-1.9.3-p448@common
|
data/lib/baidupan.rb
CHANGED
@@ -3,6 +3,7 @@ require 'multi_json'
|
|
3
3
|
|
4
4
|
require "baidupan/version"
|
5
5
|
require "baidupan/config"
|
6
|
+
require "baidupan/core_ext"
|
6
7
|
|
7
8
|
require 'pry'
|
8
9
|
|
@@ -10,7 +11,7 @@ module Baidupan
|
|
10
11
|
PAN_BASE_URL = "https://pcs.baidu.com/rest/2.0/pcs"
|
11
12
|
|
12
13
|
class Base
|
13
|
-
attr_reader :body
|
14
|
+
attr_reader :body, :response
|
14
15
|
|
15
16
|
def initialize(url, method=:get, params={}, body={}, opts={})
|
16
17
|
@options = {
|
@@ -22,6 +23,7 @@ module Baidupan
|
|
22
23
|
@options.merge!(opts)
|
23
24
|
@request = Typhoeus::Request.new(url, @options)
|
24
25
|
@request.on_complete do |response|
|
26
|
+
@response = response
|
25
27
|
if response.success?
|
26
28
|
if response.headers["Content-Disposition"] =~ /attachment;file/ or response.headers["Content-Type"] =~ /image\//
|
27
29
|
@body = response.body
|
data/lib/baidupan/cmd/fs_cmd.rb
CHANGED
@@ -10,13 +10,12 @@ module Baidupan::Cmd
|
|
10
10
|
def print_item(item)
|
11
11
|
new_items = []
|
12
12
|
new_items << item[:fs_id]
|
13
|
-
new_items << "#{item[:path].sub(Baidupan::Config.app_root + '/', '')}"
|
13
|
+
new_items << "#{item[:path].sub(Baidupan::Config.app_root + '/', '')}#{"/" if item[:isdir] == 1}"
|
14
14
|
new_items << "#{Time.at(item[:mtime])}"
|
15
15
|
print_in_columns new_items
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
19
|
desc 'list [Remote path]', 'list files under Remote path'
|
21
20
|
def list(rpath=nil)
|
22
21
|
res = Baidupan::FsCmd.list(rpath)
|
@@ -53,7 +52,6 @@ overwrite:表示覆盖同名文件;newcopy:表示生成文件副本并进
|
|
53
52
|
opts.delete(:recursive)
|
54
53
|
end
|
55
54
|
|
56
|
-
|
57
55
|
files = Dir.glob(File.join(ldir, file_pattern)).select{|f| File.file?(f)}
|
58
56
|
|
59
57
|
if options[:show]
|
@@ -97,5 +95,56 @@ overwrite:表示覆盖同名文件;newcopy:表示生成文件副本并进
|
|
97
95
|
File.binwrite(lpath, res.body)
|
98
96
|
say "download and save at'#{lpath}'..."
|
99
97
|
end
|
98
|
+
|
99
|
+
desc 'url [remote path]', 'get a stream-file url for using online, e.g. <img src="_streamurl" />'
|
100
|
+
def url(rpath)
|
101
|
+
say Baidupan::FsCmd.url(rpath)
|
102
|
+
end
|
103
|
+
|
104
|
+
desc "thumbnail rpath", "获取缩略图"
|
105
|
+
option :quality, type: :numeric, desc: "缩略图的质量,默认为“100”,取值范围(0,100]", default: 100
|
106
|
+
option :height, type: :numeric, desc: "指定缩略图的高度,取值范围为(0,1600]", default: 200
|
107
|
+
option :width, type: :numeric, desc: "指定缩略图的宽度,取值范围为(0,1600]", default: 200
|
108
|
+
def thumbnail(rpath)
|
109
|
+
opts = options.dup
|
110
|
+
say Baidupan::FsCmd.thumbnail(rpath, opts)
|
111
|
+
end
|
112
|
+
|
113
|
+
desc 'mkdir rpath', 'mkdir remote path, e.g. mkdir path/to/newdir'
|
114
|
+
def mkdir(rpath)
|
115
|
+
print_item Baidupan::FsCmd.mkdir(rpath).body
|
116
|
+
end
|
117
|
+
|
118
|
+
desc 'move from_rpath, to_rpath', 'move a remote path/to/from --> path/to/to'
|
119
|
+
def mv(from_rpath, to_rpath)
|
120
|
+
to_rpath += File.basename(from_rpath) if to_rpath[-1] == '/'
|
121
|
+
say "from_rpath不能和to_rpath相同" and return if from_rpath == to_rpath
|
122
|
+
|
123
|
+
body = Baidupan::FsCmd.move(from_rpath, to_rpath).body
|
124
|
+
|
125
|
+
say "success to mv file #{body[:extra][:list][0][:from]} ---> #{body[:extra][:list][0][:to]}"
|
126
|
+
end
|
127
|
+
|
128
|
+
desc 'copy from_rpath, to_rpath', 'copy a remote path/to/from --> path/to/to'
|
129
|
+
def copy(from_rpath, to_rpath)
|
130
|
+
to_rpath += File.basename(from_rpath) if to_rpath[-1] == '/'
|
131
|
+
say "from_rpath不能和to_rpath相同" and return if from_rpath == to_rpath
|
132
|
+
|
133
|
+
body = Baidupan::FsCmd.copy(from_rpath, to_rpath).body
|
134
|
+
say "success to cp file #{body[:extra][:list][0][:from]} ---> #{body[:extra][:list][0][:to]}"
|
135
|
+
end
|
136
|
+
map cp: :copy
|
137
|
+
|
138
|
+
desc 'delete rpath', 'delete a remote path'
|
139
|
+
option :force, type: :boolean, default: false
|
140
|
+
def delete(rpath)
|
141
|
+
if options[:force] || yes?("Are you sure to delte #{rpath}?")
|
142
|
+
response = Baidupan::FsCmd.delete(rpath).response
|
143
|
+
say "success to delete #{rpath}"if response.success?
|
144
|
+
else
|
145
|
+
say "Cancel to delete #{rpath}"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
map del: :delete
|
100
149
|
end
|
101
150
|
end
|
data/lib/baidupan/config.rb
CHANGED
@@ -19,8 +19,17 @@ module Baidupan
|
|
19
19
|
single_instance.config[method.to_sym]
|
20
20
|
end
|
21
21
|
|
22
|
-
def file_path
|
23
|
-
File.join(self.base_url, 'file')
|
22
|
+
def file_path(*files)
|
23
|
+
base_file = File.join(self.base_url, 'file')
|
24
|
+
files.each do |file|
|
25
|
+
base_file = File.join(base_file, file.to_s)
|
26
|
+
end
|
27
|
+
|
28
|
+
base_file
|
29
|
+
end
|
30
|
+
|
31
|
+
def thumbnail
|
32
|
+
File.join(self.base_url, 'thumbnail')
|
24
33
|
end
|
25
34
|
|
26
35
|
def time_format
|
@@ -29,7 +38,7 @@ module Baidupan
|
|
29
38
|
|
30
39
|
def join_path(*files)
|
31
40
|
files.inject(self.app_root) do |rpath, lpath|
|
32
|
-
File.join(rpath, lpath)
|
41
|
+
File.join(rpath, lpath.to_s)
|
33
42
|
end
|
34
43
|
end
|
35
44
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'baidupan/core_ext/hash'
|
data/lib/baidupan/fs_cmd.rb
CHANGED
@@ -6,7 +6,7 @@ module Baidupan
|
|
6
6
|
class FsCmd < Base
|
7
7
|
class << self
|
8
8
|
|
9
|
-
def list(rpath,
|
9
|
+
def list(rpath, opts={})
|
10
10
|
opts.merge!(common_params(:list, path: "#{Config.app_root}/#{rpath}"))
|
11
11
|
get(Config.file_path, opts)
|
12
12
|
end
|
@@ -22,9 +22,42 @@ module Baidupan
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def download(rpath, lpath, opts={})
|
25
|
-
params = common_params(:download, path: "#{Config.
|
25
|
+
params = common_params(:download, path: "#{Config.join(rpath)}")
|
26
26
|
get(Config.file_path, params, opts.merge(followlocation: true))
|
27
27
|
end
|
28
|
+
|
29
|
+
def url(rpath)
|
30
|
+
params = common_params(:download, path: "#{Config.join_path(rpath)}")
|
31
|
+
"#{Config.file_path}?#{params.to_query_str}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def thumbnail(rpath, opts={})
|
35
|
+
params = common_params(:generate, path: "#{Config.join_path(rpath)}").merge(opts)
|
36
|
+
"#{Config.thumbnail}?" + params.to_query_str
|
37
|
+
end
|
38
|
+
|
39
|
+
def mkdir(rpath)
|
40
|
+
post(Config.file_path, common_params(:mkdir, path: "#{Config.join_path(rpath)}"))
|
41
|
+
end
|
42
|
+
|
43
|
+
def move(from_rpath, to_rpath)
|
44
|
+
params = common_params(:move,
|
45
|
+
from: "#{Config.join_path(from_rpath)}",
|
46
|
+
to: "#{Config.join_path(to_rpath)}")
|
47
|
+
post(Config.file_path, params)
|
48
|
+
end
|
49
|
+
|
50
|
+
def copy(from_rpath, to_rpath)
|
51
|
+
params = common_params(:copy,
|
52
|
+
from: "#{Config.join_path(from_rpath)}",
|
53
|
+
to: "#{Config.join_path(to_rpath)}")
|
54
|
+
post(Config.file_path, params)
|
55
|
+
end
|
56
|
+
|
57
|
+
def delete(rpath)
|
58
|
+
params = common_params(:delete, path: "#{Config.join_path(rpath)}")
|
59
|
+
post(Config.file_path, params)
|
60
|
+
end
|
28
61
|
end
|
29
62
|
end
|
30
63
|
end
|
data/lib/baidupan/version.rb
CHANGED
metadata
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: baidupan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- AndyHu
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-29 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ~>
|
18
20
|
- !ruby/object:Gem::Version
|
@@ -20,6 +22,7 @@ dependencies:
|
|
20
22
|
type: :development
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
27
|
- - ~>
|
25
28
|
- !ruby/object:Gem::Version
|
@@ -27,20 +30,23 @@ dependencies:
|
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: rake
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
|
-
- - '>='
|
35
|
+
- - ! '>='
|
32
36
|
- !ruby/object:Gem::Version
|
33
37
|
version: '0'
|
34
38
|
type: :development
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
|
-
- - '>='
|
43
|
+
- - ! '>='
|
39
44
|
- !ruby/object:Gem::Version
|
40
45
|
version: '0'
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: typhoeus
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
51
|
- - ~>
|
46
52
|
- !ruby/object:Gem::Version
|
@@ -48,6 +54,7 @@ dependencies:
|
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
59
|
- - ~>
|
53
60
|
- !ruby/object:Gem::Version
|
@@ -55,6 +62,7 @@ dependencies:
|
|
55
62
|
- !ruby/object:Gem::Dependency
|
56
63
|
name: multi_json
|
57
64
|
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
58
66
|
requirements:
|
59
67
|
- - ~>
|
60
68
|
- !ruby/object:Gem::Version
|
@@ -62,6 +70,7 @@ dependencies:
|
|
62
70
|
type: :development
|
63
71
|
prerelease: false
|
64
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
65
74
|
requirements:
|
66
75
|
- - ~>
|
67
76
|
- !ruby/object:Gem::Version
|
@@ -69,6 +78,7 @@ dependencies:
|
|
69
78
|
- !ruby/object:Gem::Dependency
|
70
79
|
name: pry
|
71
80
|
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
72
82
|
requirements:
|
73
83
|
- - ~>
|
74
84
|
- !ruby/object:Gem::Version
|
@@ -76,6 +86,7 @@ dependencies:
|
|
76
86
|
type: :development
|
77
87
|
prerelease: false
|
78
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
79
90
|
requirements:
|
80
91
|
- - ~>
|
81
92
|
- !ruby/object:Gem::Version
|
@@ -83,6 +94,7 @@ dependencies:
|
|
83
94
|
- !ruby/object:Gem::Dependency
|
84
95
|
name: pry-nav
|
85
96
|
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
86
98
|
requirements:
|
87
99
|
- - ~>
|
88
100
|
- !ruby/object:Gem::Version
|
@@ -90,6 +102,7 @@ dependencies:
|
|
90
102
|
type: :development
|
91
103
|
prerelease: false
|
92
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
93
106
|
requirements:
|
94
107
|
- - ~>
|
95
108
|
- !ruby/object:Gem::Version
|
@@ -97,15 +110,17 @@ dependencies:
|
|
97
110
|
- !ruby/object:Gem::Dependency
|
98
111
|
name: thor
|
99
112
|
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
100
114
|
requirements:
|
101
|
-
- - '>='
|
115
|
+
- - ! '>='
|
102
116
|
- !ruby/object:Gem::Version
|
103
117
|
version: '0'
|
104
118
|
type: :runtime
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
107
122
|
requirements:
|
108
|
-
- - '>='
|
123
|
+
- - ! '>='
|
109
124
|
- !ruby/object:Gem::Version
|
110
125
|
version: '0'
|
111
126
|
description: 利用百度云盘接口, 实现文件备份功能
|
@@ -128,30 +143,33 @@ files:
|
|
128
143
|
- lib/baidupan/cmd/base.rb
|
129
144
|
- lib/baidupan/cmd/fs_cmd.rb
|
130
145
|
- lib/baidupan/config.rb
|
146
|
+
- lib/baidupan/core_ext.rb
|
147
|
+
- lib/baidupan/core_ext/hash.rb
|
131
148
|
- lib/baidupan/fs_cmd.rb
|
132
149
|
- lib/baidupan/version.rb
|
133
150
|
homepage: http://ml-china.org
|
134
151
|
licenses:
|
135
152
|
- MIT
|
136
|
-
metadata: {}
|
137
153
|
post_install_message:
|
138
154
|
rdoc_options: []
|
139
155
|
require_paths:
|
140
156
|
- lib
|
141
157
|
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
142
159
|
requirements:
|
143
|
-
- - '>='
|
160
|
+
- - ! '>='
|
144
161
|
- !ruby/object:Gem::Version
|
145
162
|
version: '0'
|
146
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
|
+
none: false
|
147
165
|
requirements:
|
148
|
-
- - '>='
|
166
|
+
- - ! '>='
|
149
167
|
- !ruby/object:Gem::Version
|
150
168
|
version: '0'
|
151
169
|
requirements: []
|
152
170
|
rubyforge_project:
|
153
|
-
rubygems_version:
|
171
|
+
rubygems_version: 1.8.25
|
154
172
|
signing_key:
|
155
|
-
specification_version:
|
173
|
+
specification_version: 3
|
156
174
|
summary: 文件上传和查看等功能
|
157
175
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: a7bf29bd9e970583b16dcc95efbe8bd58c555d81
|
4
|
-
data.tar.gz: 50a1d6c214706ab0bead3a76a36c7201dde7b63c
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: e9615c5148eff1c8ab80e5351296ff70898dc9f1fcb8dabfc62fa32b09e1c196bcd4d7757e59ec88cafe6e80c19de99843e6db2cc5721722f0989dd685bb4ab2
|
7
|
-
data.tar.gz: 63de6c09ef2a05555c8a550d0748133e3d490f37dd6bedfe8b968e977382ef7ac5bc79870e159b098062f3e633c3f44122a74b0347fb33925be5d4db9299b9a9
|