Class: Vitreous::Share::DropboxStructure

Inherits:
CommonStructure show all
Defined in:
lib/vitreous/share/dropbox_structure.rb

Instance Method Summary collapse

Methods inherited from CommonStructure

txt?

Constructor Details

#initialize(path, session) ⇒ DropboxStructure

Returns a new instance of DropboxStructure.



4
5
6
7
# File 'lib/vitreous/share/dropbox_structure.rb', line 4

def initialize( path, session )
  @path     = path
  @session  = session
end

Instance Method Details

#generateObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/vitreous/share/dropbox_structure.rb', line 9

def generate
  path = @path
  {
    'name'     => File.basename( File.dirname( path ) ),
    'path'     => '/',
    'uri'      => uri( path ),
    'type'     => 'directory',
    'elements' => tree( path ),
    'content'  => nil
  }
end

#tree(path) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vitreous/share/dropbox_structure.rb', line 21

def tree( path )
  @session.entry( path ).list.to_a.map do |e|
    {
      'name'     => File.basename( e.path ),
      'path'     => e.path.gsub( /#{@path}/i, '' ),
      'uri'      => uri( e.path ),
      'type'     => e.directory? ? 'directory' : 'file',
      'elements' => e.directory? ? tree( e.path ) : [],
      'content'  => CommonStructure.txt?( e.path ) ? @session.download( e.path ).force_encoding('utf-8') : nil
    }
  end
end

#uri(path) ⇒ Object



34
35
36
# File 'lib/vitreous/share/dropbox_structure.rb', line 34

def uri( path )
  "http://dl.dropbox.com/u/#{@session..uid}/#{path.gsub( /^\/Public\//, '' ).gsub( /^\//, '' )}"
end