Class: Dropbox::API::Client
- Inherits:
-
Object
- Object
- Dropbox::API::Client
show all
- Includes:
- Files
- Defined in:
- lib/dropbox-api/client.rb,
lib/dropbox-api/client/files.rb
Defined Under Namespace
Modules: Files
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Files
#chunked_upload, #copy_from_copy_ref, #download, #upload
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
11
12
13
14
15
16
|
# File 'lib/dropbox-api/client.rb', line 11
def initialize(options = {})
@connection = Dropbox::API::Connection.new(:token => options.delete(:token),
:secret => options.delete(:secret))
@raw = Dropbox::API::Raw.new :connection => @connection
@options = options
end
|
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
9
10
11
|
# File 'lib/dropbox-api/client.rb', line 9
def connection
@connection
end
|
Returns the value of attribute raw.
9
10
11
|
# File 'lib/dropbox-api/client.rb', line 9
def raw
@raw
end
|
Instance Method Details
29
30
31
|
# File 'lib/dropbox-api/client.rb', line 29
def account
Dropbox::API::Object.init(self.raw.account, self)
end
|
#delta(cursor = nil, options = {}) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/dropbox-api/client.rb', line 51
def delta(cursor=nil, options={})
entries = []
has_more = true
params = cursor ? options.merge(:cursor => cursor) : options
while has_more
response = raw.delta(params)
params[:cursor] = response['cursor']
has_more = response['has_more']
entries.push *response['entries']
end
files = entries.map do |entry|
entry.last || {:is_deleted => true, :path => entry.first}
end
Delta.new(params[:cursor], Dropbox::API::Object.convert(files, self))
end
|
#destroy(path, options = {}) ⇒ Object
40
41
42
43
|
# File 'lib/dropbox-api/client.rb', line 40
def destroy(path, options = {})
response = raw.delete({ :path => path }.merge(options))
Dropbox::API::Object.convert(response, self)
end
|
#find(filename) ⇒ Object
20
21
22
23
|
# File 'lib/dropbox-api/client.rb', line 20
def find(filename)
data = self.raw.metadata(:path => filename, :list => false)
Dropbox::API::Object.convert(data, self)
end
|
#ls(path = '') ⇒ Object
25
26
27
|
# File 'lib/dropbox-api/client.rb', line 25
def ls(path = '')
Dropbox::API::Dir.init({'path' => path}, self).ls
end
|
#mkdir(path) ⇒ Object
33
34
35
36
37
38
|
# File 'lib/dropbox-api/client.rb', line 33
def mkdir(path)
path = path.gsub(/[\\\:\?\*\<\>\"\|]+/, '')
response = raw.create_folder :path => path
Dropbox::API::Dir.init(response, self)
end
|
#search(term, options = {}) ⇒ Object
45
46
47
48
49
|
# File 'lib/dropbox-api/client.rb', line 45
def search(term, options = {})
options[:path] ||= ''
results = raw.search({ :query => term }.merge(options))
Dropbox::API::Object.convert(results, self)
end
|