Class: Dropbox::Entry

Inherits:
Object show all
Defined in:
lib/dropbox/entry.rb

Overview

A façade over a Dropbox::Session that allows the programmer to interact with Dropbox files in an object-oriented manner. The Dropbox::Entry instance is created by calling the Dropbox::API#entry method:

file = session.file('remote/file.pdf')
dir = session.directory('remote/dir') # these calls are actually identical

Note that no network calls are made; this merely creates a façade that will delegate future calls to the session:

file.move('new/path') # identical to calling session.move('remote/file.pdf', 'new/path')

The internal path is updated as the file is moved and renamed:

file = session.file('first_name.txt')
file.rename('second_name.txt')
file.rename('third_name.txt') # works as the internal path is updated with the first rename

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session, path) ⇒ Entry

:nodoc:



29
30
31
32
# File 'lib/dropbox/entry.rb', line 29

def initialize(session, path) # :nodoc:
  @session = session
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

The remote path of the file.



27
28
29
# File 'lib/dropbox/entry.rb', line 27

def path
  @path
end

Instance Method Details

#copy(dest, options = {}) ⇒ Object Also known as: cp

Delegates to Dropbox::API#copy.



73
74
75
# File 'lib/dropbox/entry.rb', line 73

def copy(dest, options={})
  @session.copy path, dest, options
end

#delete(options = {}) ⇒ Object Also known as: rm

Delegates to Dropbox::API#delete.



80
81
82
# File 'lib/dropbox/entry.rb', line 80

def delete(options={})
  @session.delete path, options
end

#download(options = {}) ⇒ Object Also known as: body

Delegates to Dropbox::API#download.



87
88
89
# File 'lib/dropbox/entry.rb', line 87

def download(options={})
  @session.download path, options
end

#inspectObject

:nodoc:



104
105
106
# File 'lib/dropbox/entry.rb', line 104

def inspect # :nodoc:
  "#<#{self.class.to_s} #{path}>"
end

Delegates to Dropbox::API#link.



100
101
102
# File 'lib/dropbox/entry.rb', line 100

def link(options={})
  @session.link path, options
end

#list(options = {}) ⇒ Object Also known as: ls

Delegates to Dropbox::API#list



49
50
51
# File 'lib/dropbox/entry.rb', line 49

def list(options={})
  @session.list path, options
end

#metadata(options = {}) ⇒ Object Also known as: info

Delegates to Dropbox::API#metadata. Additional options:

force

Normally, subsequent calls to this method will use cached results if the file hasn’t been changed. To download the full metadata even if the file has not been changed, set this to true.



41
42
43
44
# File 'lib/dropbox/entry.rb', line 41

def (options={})
  @previous_metadata = nil if options.delete(:force)
  @previous_metadata = @session. path, (@previous_metadata ? options.merge(:prior_response => @previous_metadata) : options)
end

#move(dest, options = {}) ⇒ Object Also known as: mv

Delegates to Dropbox::API#move.



56
57
58
59
60
# File 'lib/dropbox/entry.rb', line 56

def move(dest, options={})
  result = @session.move(path, dest, options)
  @path = result.path.gsub(/^\//, '')
  return result
end

#rename(name, options = {}) ⇒ Object

Delegates to Dropbox::API#rename.



65
66
67
68
69
# File 'lib/dropbox/entry.rb', line 65

def rename(name, options={})
  result = @session.rename(path, name, options)
  @path = result.path.gsub(/^\//, '')
  return result
end

#thumbnail(*args) ⇒ Object

Delegates to Dropbox::API#thumbnail.



94
95
96
# File 'lib/dropbox/entry.rb', line 94

def thumbnail(*args)
  @session.thumbnail path, *args
end