Class: Egnyte::Folder

Inherits:
Item
  • Object
show all
Defined in:
lib/egnyte/folder.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Item

#fs_path, #initialize, #method_missing, #update_data

Constructor Details

This class inherits a constructor from Egnyte::Item

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Egnyte::Item

Class Method Details

.find(session, path) ⇒ Object

Raises:



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/egnyte/folder.rb', line 47

def self.find(session, path)
  path = Egnyte::Helper.normalize_path(path)

  folder = Folder.new({
    'path' => path
  }, session)
  
  parsed_body = session.get("#{folder.fs_path}#{URI.escape(path)}")

  raise FolderExpected unless parsed_body['is_folder']

  folder.update_data(parsed_body)
end

Instance Method Details

#create(path) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/egnyte/folder.rb', line 3

def create(path)
  path = Egnyte::Helper.normalize_path(path)

  new_folder_path = "#{self.path}/#{path}"

  @session.post("#{fs_path}#{URI.escape(new_folder_path)}", JSON.dump({
    action: 'add_folder'
  }))

  Folder.new({
    'path' => new_folder_path,
    'folders' => [],
    'is_folder' => true,
    'name' => new_folder_path.split('/').pop
  }, @session)
end

#deleteObject



20
21
22
# File 'lib/egnyte/folder.rb', line 20

def delete
  @session.delete("#{fs_path}/#{URI.escape(path)}")
end

#filesObject



39
40
41
# File 'lib/egnyte/folder.rb', line 39

def files
  create_objects(File, 'files')
end

#foldersObject



43
44
45
# File 'lib/egnyte/folder.rb', line 43

def folders
  create_objects(Folder, 'folders')
end

#upload(filename, content) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/egnyte/folder.rb', line 24

def upload(filename, content)
  resp = @session.multipart_post("#{fs_path('fs-content')}#{URI.escape(path)}/#{URI.escape(filename)}", filename, content, false)

  content.rewind # to calculate size, rewind content stream.

  File.new({
    'is_folder' => false,
    'entry_id' => resp['ETag'],
    'checksum' => resp['X-Sha512-Checksum'],
    'last_modified' => resp['Last-Modified'],
    'name' => filename,
    'size' => content.size
  }, @session)
end