Class: Dropbox::API::Client

Inherits:
Object
  • Object
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

#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

#connectionObject

Returns the value of attribute connection.



9
10
11
# File 'lib/dropbox-api/client.rb', line 9

def connection
  @connection
end

#rawObject

Returns the value of attribute raw.



9
10
11
# File 'lib/dropbox-api/client.rb', line 9

def raw
  @raw
end

Instance Method Details

#accountObject



35
36
37
# File 'lib/dropbox-api/client.rb', line 35

def 
  Dropbox::API::Object.init(self.raw., self)
end

#delta(cursor = nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/dropbox-api/client.rb', line 52

def delta(cursor=nil)
  entries  = []
  has_more = true
  params   = cursor ? {:cursor => cursor} : {}
  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

#find(filename) ⇒ Object



20
21
22
23
24
# File 'lib/dropbox-api/client.rb', line 20

def find(filename)
  data = self.raw.(:path => filename)
  data.delete('contents')
  Dropbox::API::Object.convert(data, self)
end

#folder_changed?(path = '', hash = '') ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/dropbox-api/client.rb', line 30

def folder_changed?(path = '', hash = '')
  meta_response = Dropbox::API::Dir.init({'path' => path}, self).folder_meta(path,hash)
  return (meta_response.kind_of? Dropbox::API::Response::NotModified) ? false : meta_response
end

#ls(path = '') ⇒ Object



26
27
28
# File 'lib/dropbox-api/client.rb', line 26

def ls(path = '')
  Dropbox::API::Dir.init({'path' => path}, self).ls
end

#mkdir(path) ⇒ Object



39
40
41
42
43
44
# File 'lib/dropbox-api/client.rb', line 39

def mkdir(path)
  # Remove the characters not allowed by Dropbox
  path = path.gsub(/[\\\:\?\*\<\>\"\|]+/, '')
  response = raw.create_folder :path => path
  Dropbox::API::Dir.init(response, self)
end

#search(term, options = {}) ⇒ Object



46
47
48
49
50
# File 'lib/dropbox-api/client.rb', line 46

def search(term, options = {})
  options[:path] ||= ''
  results = raw.search({ :query => term }.merge(options))
  Dropbox::API::Object.convert(results, self)
end