Class: Kuaipan::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/kuaipan/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(consumer) ⇒ Base

Returns a new instance of Base.



7
8
9
# File 'lib/kuaipan/base.rb', line 7

def initialize(consumer)
  @consumer = consumer
end

Instance Attribute Details

#oauth_tokenObject (readonly)

Returns the value of attribute oauth_token.



5
6
7
# File 'lib/kuaipan/base.rb', line 5

def oauth_token
  @oauth_token
end

Instance Method Details

#account_infoObject



11
12
13
14
# File 'lib/kuaipan/base.rb', line 11

def 
  res =  @consumer.get_no_ssl('account_info')
  parse_response(res)
end

#copy(from_path, to_path, opts = {}) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/kuaipan/base.rb', line 36

def copy(from_path, to_path, opts={})
  res = @consumer.get_no_ssl('fileops/copy',
                              {from_path: from_path,
                               to_path: to_path,
                               root: 'app_folder'}.merge(opts))
  parse_response(res)
end

#create_folder(folder, opts = {}) ⇒ Object



97
98
99
100
101
102
103
104
# File 'lib/kuaipan/base.rb', line 97

def create_folder(folder, opts={})
  folder = folder.encode('UTF-8')
  return nil if folder.size > 255
  res = @consumer.get_no_ssl('fileops/create_folder', 
                              {root: 'app_folder',
                               path: folder}.merge(opts))
  parse_response(res)
end

#delete(path, opts = {}) ⇒ Object



106
107
108
109
110
111
112
# File 'lib/kuaipan/base.rb', line 106

def delete(path, opts={})
  res = @consumer.get_no_ssl('fileops/delete', 
                       {root: 'app_folder',
                        path: path,
                        to_recycle: 'True'}.merge(opts))
  parse_response(res)
end

#document_view(type, path, opts = {}, &block) ⇒ Object

Raises:



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/kuaipan/base.rb', line 63

def document_view(type, path, opts={},  &block)
  raise NoTypeError.new("No type:#{ type }") if Config[:types].index(type.to_s) == nil
  raise NoViewError("No view:#{ opts[:view] }") if (opts[:views] and (Config[:view].index(opts[:view].to_s) == nil))
  res = @consumer.get_no_ssl('fileops/documentView',
                             {view: 'normal',
                              zip: 0,
                              root: 'app_folder',
                              path: path,
                              type: type,
                              site: Config[:thum_doc_site]
                             }.merge(opts))
  parse_response(res, &block)
end

#download_file(path, opts = {}, &block) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/kuaipan/base.rb', line 44

def download_file(path, opts={}, &block)
  res = @consumer.get_no_ssl('fileops/download_file',
                              {root: 'app_folder',
                               path: path,
                               site: Config[:up_down_file_stie]}.merge(opts))
  parse_response(res, &block)
end

#metadata(path, opts = {}) ⇒ Object



16
17
18
19
20
# File 'lib/kuaipan/base.rb', line 16

def (path ,opts={})
  root = opts[:root] ? opts[:root].to_s : 'app_folder'
  res = @consumer.get_no_ssl(urlencode("metadata/#{ root }#{ path }"),opts)
  parse_response(res)
end

#move(from_path, to_path, opts = {}) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/kuaipan/base.rb', line 28

def move(from_path, to_path, opts={})
  res = @consumer.get_no_ssl('fileops/move',
                              {from_path: from_path,
                               to_path: to_path,
                               root: 'app_folder'}.merge(opts))
  parse_response(res)
end

#shares(path, opts = {}) ⇒ Object



22
23
24
25
26
# File 'lib/kuaipan/base.rb', line 22

def shares(path, opts={})
  root = opts[:root] ? opts[:root].to_s : 'app_folder'
  res = @consumer.get_no_ssl(urlencode("shares/#{ root }#{ path }"),opts)
  parse_response(res)
end

#thumbnail(width, height, path, opts = {}, &block) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/kuaipan/base.rb', line 52

def thumbnail(width, height, path, opts={}, &block)
  res = @consumer.get_no_ssl('fileops/thumbnail',
                              {width: width,
                               height: height,
                               path: path,
                               root: 'app_folder',
                               site: Config[:thum_doc_site]}.merge(opts))
  parse_response(res, &block)
end

#upload_file(file, opts = {}) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/kuaipan/base.rb', line 84

def upload_file(file, opts={}) 
  folder = opts[:path]
  opts[:path] = opts[:path] ? "/#{ opts[:path] }/#{ File.basename(file.path) }"
                            : File.basename(file.path)  
  opts[:root] =  'app_folder' unless opts[:root]
  create_folder((folder ||= ''), :root => opts[:root])
  body = @consumer.post('fileops/upload_file', 
                        file,
                        {overwrite: 'True', 
                         site: upload_locate['url'],}.merge(opts))
  JSON.parse(body)
end

#upload_locateObject



77
78
79
80
81
# File 'lib/kuaipan/base.rb', line 77

def upload_locate
  res = @consumer.get_no_ssl('/fileops/upload_locate', 
                              {site: Config[:up_down_file_stie]})
  parse_response(res)
end