Class: Baidupan::FsCmd

Inherits:
Base
  • Object
show all
Defined in:
lib/baidupan/fs_cmd.rb

Instance Attribute Summary

Attributes inherited from Base

#body, #response

Class Method Summary collapse

Methods inherited from Base

common_params, get, #initialize, post, #run!

Constructor Details

This class inherits a constructor from Baidupan::Base

Class Method Details

.copy(from_rpath, to_rpath) ⇒ Object



50
51
52
53
54
55
# File 'lib/baidupan/fs_cmd.rb', line 50

def copy(from_rpath, to_rpath)
  params = common_params(:copy, 
                         from: "#{Config.join_path(from_rpath)}",
                         to: "#{Config.join_path(to_rpath)}")
  post(Config.file_path, params)
end

.delete(rpath) ⇒ Object



57
58
59
60
# File 'lib/baidupan/fs_cmd.rb', line 57

def delete(rpath)
  params = common_params(:delete, path: "#{Config.join_path(rpath)}")
  post(Config.file_path, params)
end

.download(rpath, lpath, opts = {}) ⇒ Object



24
25
26
27
# File 'lib/baidupan/fs_cmd.rb', line 24

def download(rpath, lpath, opts={})
	params = common_params(:download, path: "#{Config.join_path(rpath)}")
get(Config.file_path, params, opts.merge(followlocation: true))
end

.list(rpath, opts = {}) ⇒ Object



9
10
11
12
# File 'lib/baidupan/fs_cmd.rb', line 9

def list(rpath, opts={})
  opts.merge!(common_params(:list, path: "#{Config.app_root}/#{rpath}"))
  get(Config.file_path, opts)
end

.mkdir(rpath) ⇒ Object



39
40
41
# File 'lib/baidupan/fs_cmd.rb', line 39

def mkdir(rpath)
  post(Config.file_path, common_params(:mkdir, path: "#{Config.join_path(rpath)}"))
end

.move(from_rpath, to_rpath) ⇒ Object



43
44
45
46
47
48
# File 'lib/baidupan/fs_cmd.rb', line 43

def move(from_rpath, to_rpath)
  params = common_params(:move, 
                         from: "#{Config.join_path(from_rpath)}",
                         to: "#{Config.join_path(to_rpath)}")
  post(Config.file_path, params)
end

.quotaObject



62
63
64
65
# File 'lib/baidupan/fs_cmd.rb', line 62

def quota
  params = common_params(:info)
  get(Config.other_api_path(:quota), params)
end

.thumbnail(rpath, opts = {}) ⇒ Object



34
35
36
37
# File 'lib/baidupan/fs_cmd.rb', line 34

def thumbnail(rpath, opts={})
  params = common_params(:generate, path: "#{Config.join_path(rpath)}").merge(opts)
  "#{Config.thumbnail}?" + params.to_query_str
end

.upload(lpath, rpath, opts = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/baidupan/fs_cmd.rb', line 14

def upload(lpath, rpath, opts={})
	params = common_params(:upload, path: "#{Config.join_path(rpath, File.basename(lpath))}").merge(ondup: :newcopy)
	params[:ondup] = opts.delete(:ondup) if opts[:ondup]
  
  body = {:file => File.open(lpath)}
  opts[:noprogress] ||= true

	post(Config.file_path, params, body, opts)
end

.url(rpath) ⇒ Object



29
30
31
32
# File 'lib/baidupan/fs_cmd.rb', line 29

def url(rpath)
  params = common_params(:download, path: "#{Config.join_path(rpath)}")
  "#{Config.file_path}?#{params.to_query_str}"
end