Class: Egnyte::File

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

Instance Attribute Summary

Attributes inherited from Item

#session

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Item

#copy, fs_path, #fs_path, #initialize, #method_missing, #move, #move_or_copy, #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:



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/egnyte/file.rb', line 36

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

  file = File.new({
    'path' => path
  }, session)

  parsed_body = session.get("#{file.fs_path}#{path}")

  raise FileExpected if parsed_body['is_folder']

  file.update_data(parsed_body)
end

Instance Method Details

#deleteObject



32
33
34
# File 'lib/egnyte/file.rb', line 32

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

#downloadObject



13
14
15
# File 'lib/egnyte/file.rb', line 13

def download
  stream.read
end

#download_version(entry_id) ⇒ Object



17
18
19
# File 'lib/egnyte/file.rb', line 17

def download_version(entry_id)
  stream(:entry_id => entry_id).read
end

#stream(opts = {}) ⇒ Object

use opts to provide lambdas to track the streaming download:

:content_length_proc :progress_proc



26
27
28
29
30
# File 'lib/egnyte/file.rb', line 26

def stream( opts={} )
  file_content_path = "#{fs_path('fs-content')}#{Egnyte::Helper.normalize_path(path)}"
  file_content_path += "?entry_id=#{opts[:entry_id]}" if opts[:entry_id]
  @session.streaming_download(file_content_path, opts )
end