Class: BaiduPcs::Fs
Constant Summary
collapse
- FILE_BASE_URL =
"#{PCS_BASE_URL}/file"
Instance Attribute Summary
Attributes inherited from Base
#body, #options, #request, #response
Class Method Summary
collapse
Methods inherited from Base
atoken_params, get, #http_code, #initialize, method_params, #ok?, post, put, quota, #run!
Constructor Details
This class inherits a constructor from BaiduPcs::Base
Class Method Details
.copy(from_rpath, to_rpath) ⇒ Object
51
52
53
54
55
56
|
# File 'lib/baidu_pcs/fs.rb', line 51
def self.copy(from_rpath, to_rpath)
params = method_params(:copy,
from: "#{Config.app_root}/#{from_rpath}",
to: "#{Config.app_root}/#{to_rpath}")
post(FILE_BASE_URL, params)
end
|
.delete(rpath) ⇒ Object
文件/目录删除后默认临时存放在回收站内;10天后永久删除
59
60
61
62
|
# File 'lib/baidu_pcs/fs.rb', line 59
def self.delete(rpath)
params = method_params(:delete, path: "#{Config.app_root}/#{rpath}")
post(FILE_BASE_URL, params)
end
|
.download(rpath, opts = {}) ⇒ Object
19
20
21
22
|
# File 'lib/baidu_pcs/fs.rb', line 19
def self.download(rpath, opts={})
params = method_params(:download, path: "#{Config.app_root}/#{rpath}")
get(FILE_BASE_URL, params, opts)
end
|
.list(rpath = nil, opts = {}) ⇒ Object
39
40
41
42
|
# File 'lib/baidu_pcs/fs.rb', line 39
def self.list(rpath=nil, opts={})
params = method_params(:list, path: "#{Config.app_root}/#{rpath}").merge(opts)
get(FILE_BASE_URL, params)
end
|
35
36
37
|
# File 'lib/baidu_pcs/fs.rb', line 35
def self.meta(rpath)
get(FILE_BASE_URL, method_params(:meta, path: "#{Config.app_root}/#{rpath}"))
end
|
.mkdir(rpath) ⇒ Object
31
32
33
|
# File 'lib/baidu_pcs/fs.rb', line 31
def self.mkdir(rpath)
post(FILE_BASE_URL, method_params(:mkdir, path: "#{Config.app_root}/#{rpath}"))
end
|
.move(from_rpath, to_rpath) ⇒ Object
44
45
46
47
48
49
|
# File 'lib/baidu_pcs/fs.rb', line 44
def self.move(from_rpath, to_rpath)
params = method_params(:move,
from: "#{Config.app_root}/#{from_rpath}",
to: "#{Config.app_root}/#{to_rpath}")
post(FILE_BASE_URL, params)
end
|
.search(keyword, rpath, opts = {}) ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/baidu_pcs/fs.rb', line 64
def self.search(keyword, rpath, opts = {})
params = method_params(:search,
wd: keyword,
path: "#{Config.app_root}/#{rpath}")
params[:re] = opts[:recursive] ? '1' : '0'
get(FILE_BASE_URL, params)
end
|
.streamurl(rpath) ⇒ Object
25
26
27
28
29
|
# File 'lib/baidu_pcs/fs.rb', line 25
def self.streamurl(rpath)
params = method_params(:download, path: "#{Config.app_root}/#{rpath}")
query_str = params.map{|k, v| "#{k}=#{v}"}.join("&") "#{FILE_BASE_URL}?#{query_str}"
end
|
.upload(path, rpath = nil, opts = {}) ⇒ Object
path: local file path rpath: 上传文件路径(含上传的文件名称)
13
14
15
16
17
|
# File 'lib/baidu_pcs/fs.rb', line 13
def self.upload(path, rpath=nil, opts={})
params = method_params(:upload, path: "#{Config.app_root}/#{rpath||File.basename(path)}")
params[:ondup] = opts.delete(:ondup) if opts[:ondup]
post(FILE_BASE_URL, params, {file: File.open(path)}, opts)
end
|