Class: Files::Folder

Inherits:
Object
  • Object
show all
Defined in:
lib/files.com/models/folder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Folder

Returns a new instance of Folder.



102
103
104
105
106
# File 'lib/files.com/models/folder.rb', line 102

def initialize(*args)
  @attributes = (args[0].is_a?(Hash) && args[0]) || {}
  @options = (args[1].is_a?(Hash) && args[1]) || {}
  @attributes['path'] = args[0] if args[0].is_a?(String)
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



5
6
7
# File 'lib/files.com/models/folder.rb', line 5

def attributes
  @attributes
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/files.com/models/folder.rb', line 5

def options
  @options
end

#posObject



126
127
128
# File 'lib/files.com/models/folder.rb', line 126

def pos
  @pos ||= 0
end

Class Method Details

.[](*_) ⇒ Object



6
7
8
# File 'lib/files.com/models/folder.rb', line 6

def self.[](*_)
  raise NotImplementedError
end

.chdir(path, &block) ⇒ Object

Raises:

  • (Errno::ENOENT)


10
11
12
13
14
15
16
17
18
# File 'lib/files.com/models/folder.rb', line 10

def self.chdir(path, &block)
  raise Errno::ENOENT.new(path) if exist? path

  if block
    yield path
  else
    @@path ||= path
  end
end

.children(path, _encoding = "") ⇒ Object



20
21
22
# File 'lib/files.com/models/folder.rb', line 20

def self.children(path, _encoding = "")
  Folder.new(path).contents.map(&:path)
end

.chroot(*args) ⇒ Object



24
# File 'lib/files.com/models/folder.rb', line 24

def self.chroot(*args); end

.create(path, params = {}, options = {}) ⇒ Object

Parameters:

path (required) - string - Path to operate on.


345
346
347
348
349
350
351
352
353
# File 'lib/files.com/models/folder.rb', line 345

def self.create(path, params = {}, options = {})
  params ||= {}
  params[:path] = path
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String)
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)

  response, options = Api.send_request("/folders/#{Addressable::URI.encode_component(params[:path])}", :post, params, options)
  File.new(response.data, options)
end

.delete(path, params = {}, options = {}) ⇒ Object



26
27
28
# File 'lib/files.com/models/folder.rb', line 26

def self.delete(path, params = {}, options = {})
  File.delete(path, params, options)
end

.destroy(path, params = {}, options = {}) ⇒ Object



30
31
32
# File 'lib/files.com/models/folder.rb', line 30

def self.destroy(path, params = {}, options = {})
  File.destroy(path, params, options)
end

.each_child(path, _encoding = "", &block) ⇒ Object



34
35
36
# File 'lib/files.com/models/folder.rb', line 34

def self.each_child(path, _encoding = "", &block)
  Folder.new(path).each(&block)
end

.empty?(*_args) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/files.com/models/folder.rb', line 38

def self.empty?(*_args)
  Folder.new(path).contents.empty?
end

.entries(path) ⇒ Object



42
43
44
# File 'lib/files.com/models/folder.rb', line 42

def self.entries(path)
  list(path)
end

.exist?(*args) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/files.com/models/folder.rb', line 46

def self.exist?(*args)
  File.exist?(*args)
end

.find(path, params = {}, options = {}) ⇒ Object



50
51
52
# File 'lib/files.com/models/folder.rb', line 50

def self.find(path, params = {}, options = {})
  File.find(path, params, options)
end

.foreach(path, _encoding = "", params = {}, options = {}) ⇒ Object



58
59
60
# File 'lib/files.com/models/folder.rb', line 58

def self.foreach(path, _encoding = "", params = {}, options = {})
  list_for(path, params, options).each { |x| yield x }
end

.get(path, params = {}, options = {}) ⇒ Object



54
55
56
# File 'lib/files.com/models/folder.rb', line 54

def self.get(path, params = {}, options = {})
  File.get(path, params, options)
end

.getwd(*_args) ⇒ Object



62
63
64
# File 'lib/files.com/models/folder.rb', line 62

def self.getwd(*_args)
  pwd
end

.glob(*_) ⇒ Object



66
67
68
# File 'lib/files.com/models/folder.rb', line 66

def self.glob(*_)
  raise NotImplementedError
end

.home(*_args) ⇒ Object



70
71
72
# File 'lib/files.com/models/folder.rb', line 70

def self.home(*_args)
  ""
end

.list_for(path, params = {}, options = {}) ⇒ Object

Parameters:

page - int64 - Current page number.
per_page - int64 - Number of records to show per page.  (Max: 10,000, 1,000 or less is recommended).
action - string - Action to take.  Can be `count`, `count_nrs` (non recursive), `size`, `permissions`, or blank.
path (required) - string - Path to operate on.
cursor - string - Send cursor to resume an existing list from the point at which you left off.  Get a cursor from an existing list via the X-Files-Cursor header.
filter - string - If specified, will to filter folders/files list by this string.  Wildcards of `*` and `?` are acceptable here.
preview_size - string - Request a preview size.  Can be `small` (default), `large`, `xlarge`, or `pdf`.
search - string - If `search_all` is `true`, provide the search string here.  Otherwise, this parameter acts like an alias of `filter`.
search_all - boolean - Search entire site?
with_priority_color - boolean - Include file priority color information?


325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/files.com/models/folder.rb', line 325

def self.list_for(path, params = {}, options = {})
  params ||= {}
  params[:path] = path
  raise InvalidParameterError.new("Bad parameter: page must be an Integer") if params.dig(:page) and !params.dig(:page).is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: per_page must be an Integer") if params.dig(:per_page) and !params.dig(:per_page).is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: cursor must be an String") if params.dig(:cursor) and !params.dig(:cursor).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: filter must be an String") if params.dig(:filter) and !params.dig(:filter).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: preview_size must be an String") if params.dig(:preview_size) and !params.dig(:preview_size).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: search must be an String") if params.dig(:search) and !params.dig(:search).is_a?(String)
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)

  List.new(File, params) do
    Api.send_request("/folders/#{Addressable::URI.encode_component(params[:path])}", :get, params, options)
  end
end

.mkdir(path, params = {}, options = {}) ⇒ Object



74
75
76
# File 'lib/files.com/models/folder.rb', line 74

def self.mkdir(path, params = {}, options = {})
  create(path, params, options)
end

.open(*args, &block) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/files.com/models/folder.rb', line 78

def self.open(*args, &block)
  if block.nil?
    new *args
  else
    yield new *args
  end
end

.pwd(*_args) ⇒ Object



86
87
88
# File 'lib/files.com/models/folder.rb', line 86

def self.pwd(*_args)
  @@path ||= ""
end

.rmdir(path) ⇒ Object



90
91
92
# File 'lib/files.com/models/folder.rb', line 90

def self.rmdir(path)
  delete(path)
end


94
95
96
# File 'lib/files.com/models/folder.rb', line 94

def self.unlink(path)
  delete(path)
end

.update(path, params = {}, options = {}) ⇒ Object



98
99
100
# File 'lib/files.com/models/folder.rb', line 98

def self.update(path, params = {}, options = {})
  File.update(path, params, options)
end

Instance Method Details

#close(*args) ⇒ Object



108
# File 'lib/files.com/models/folder.rb', line 108

def close(*args); end

#contentsObject



118
119
120
# File 'lib/files.com/models/folder.rb', line 118

def contents
  @contents ||= Folder.list(path, {}, @options)
end

#crc32Object

string - File CRC32 checksum. This is sometimes delayed, so if you get a blank response, wait and try again.



216
217
218
# File 'lib/files.com/models/folder.rb', line 216

def crc32
  @attributes[:crc32]
end

#crc32=(value) ⇒ Object



220
221
222
# File 'lib/files.com/models/folder.rb', line 220

def crc32=(value)
  @attributes[:crc32] = value
end

#display_nameObject

string - File/Folder display name



171
172
173
# File 'lib/files.com/models/folder.rb', line 171

def display_name
  @attributes[:display_name]
end

#display_name=(value) ⇒ Object



175
176
177
# File 'lib/files.com/models/folder.rb', line 175

def display_name=(value)
  @attributes[:display_name] = value
end

#download_uriObject

string - Link to download file. Provided only in response to a download request.



270
271
272
# File 'lib/files.com/models/folder.rb', line 270

def download_uri
  @attributes[:download_uri]
end

#download_uri=(value) ⇒ Object



274
275
276
# File 'lib/files.com/models/folder.rb', line 274

def download_uri=(value)
  @attributes[:download_uri] = value
end

#eachObject



110
111
112
# File 'lib/files.com/models/folder.rb', line 110

def each
  contents.each { |x| yield x }
end

#filenoObject



114
115
116
# File 'lib/files.com/models/folder.rb', line 114

def fileno
  stats.id
end

#idObject

int64 - File/Folder ID



153
154
155
# File 'lib/files.com/models/folder.rb', line 153

def id
  @attributes[:id]
end

#id=(value) ⇒ Object



157
158
159
# File 'lib/files.com/models/folder.rb', line 157

def id=(value)
  @attributes[:id] = value
end

#md5Object

string - File MD5 checksum. This is sometimes delayed, so if you get a blank response, wait and try again.



225
226
227
# File 'lib/files.com/models/folder.rb', line 225

def md5
  @attributes[:md5]
end

#md5=(value) ⇒ Object



229
230
231
# File 'lib/files.com/models/folder.rb', line 229

def md5=(value)
  @attributes[:md5] = value
end

#mime_typeObject

string - MIME Type. This is determined by the filename extension and is not stored separately internally.



234
235
236
# File 'lib/files.com/models/folder.rb', line 234

def mime_type
  @attributes[:mime_type]
end

#mime_type=(value) ⇒ Object



238
239
240
# File 'lib/files.com/models/folder.rb', line 238

def mime_type=(value)
  @attributes[:mime_type] = value
end

#mtimeObject

date-time - File last modified date/time, according to the server. This is the timestamp of the last Files.com operation of the file, regardless of what modified timestamp was sent.



198
199
200
# File 'lib/files.com/models/folder.rb', line 198

def mtime
  @attributes[:mtime]
end

#mtime=(value) ⇒ Object



202
203
204
# File 'lib/files.com/models/folder.rb', line 202

def mtime=(value)
  @attributes[:mtime] = value
end

#pathObject

string - File/Folder path This must be slash-delimited, but it must neither start nor end with a slash. Maximum of 5000 characters.



162
163
164
# File 'lib/files.com/models/folder.rb', line 162

def path
  @attributes[:path]
end

#path=(value) ⇒ Object



166
167
168
# File 'lib/files.com/models/folder.rb', line 166

def path=(value)
  @attributes[:path] = value
end

#permissionsObject

string - A short string representing the current user’s permissions. Can be ‘r`,`w`,`p`, or any combination



252
253
254
# File 'lib/files.com/models/folder.rb', line 252

def permissions
  @attributes[:permissions]
end

#permissions=(value) ⇒ Object



256
257
258
# File 'lib/files.com/models/folder.rb', line 256

def permissions=(value)
  @attributes[:permissions] = value
end

#previewObject

File preview



297
298
299
# File 'lib/files.com/models/folder.rb', line 297

def preview
  @attributes[:preview]
end

#preview=(value) ⇒ Object



301
302
303
# File 'lib/files.com/models/folder.rb', line 301

def preview=(value)
  @attributes[:preview] = value
end

#preview_idObject

int64 - File preview ID



288
289
290
# File 'lib/files.com/models/folder.rb', line 288

def preview_id
  @attributes[:preview_id]
end

#preview_id=(value) ⇒ Object



292
293
294
# File 'lib/files.com/models/folder.rb', line 292

def preview_id=(value)
  @attributes[:preview_id] = value
end

#priority_colorObject

string - Bookmark/priority color of file/folder



279
280
281
# File 'lib/files.com/models/folder.rb', line 279

def priority_color
  @attributes[:priority_color]
end

#priority_color=(value) ⇒ Object



283
284
285
# File 'lib/files.com/models/folder.rb', line 283

def priority_color=(value)
  @attributes[:priority_color] = value
end

#provided_mtimeObject

date-time - File last modified date/time, according to the client who set it. Files.com allows desktop, FTP, SFTP, and WebDAV clients to set modified at times. This allows Desktop<->Cloud syncing to preserve modified at times.



207
208
209
# File 'lib/files.com/models/folder.rb', line 207

def provided_mtime
  @attributes[:provided_mtime]
end

#provided_mtime=(value) ⇒ Object



211
212
213
# File 'lib/files.com/models/folder.rb', line 211

def provided_mtime=(value)
  @attributes[:provided_mtime] = value
end

#read(*_args) ⇒ Object



132
133
134
# File 'lib/files.com/models/folder.rb', line 132

def read(*_args)
  contents[@pos]
end

#regionObject

string - Region location



243
244
245
# File 'lib/files.com/models/folder.rb', line 243

def region
  @attributes[:region]
end

#region=(value) ⇒ Object



247
248
249
# File 'lib/files.com/models/folder.rb', line 247

def region=(value)
  @attributes[:region] = value
end

#rewindObject



136
137
138
# File 'lib/files.com/models/folder.rb', line 136

def rewind
  @pos = 0
end

#saveObject



305
306
307
308
309
310
311
312
# File 'lib/files.com/models/folder.rb', line 305

def save
  if @attributes[:path]
    raise NotImplementedError.new("The Folder object doesn't support updates.")
  else
    new_obj = Folder.create(@attributes, @options)
    @attributes = new_obj.attributes
  end
end

#seek(pos) ⇒ Object



140
141
142
# File 'lib/files.com/models/folder.rb', line 140

def seek(pos)
  @pos = pos
end

#sizeObject

int64 - File/Folder size



189
190
191
# File 'lib/files.com/models/folder.rb', line 189

def size
  @attributes[:size]
end

#size=(value) ⇒ Object



193
194
195
# File 'lib/files.com/models/folder.rb', line 193

def size=(value)
  @attributes[:size] = value
end

#statsObject



122
123
124
# File 'lib/files.com/models/folder.rb', line 122

def stats
  @stats ||= File.download(@filename, { "action": "stat" }, @options)
end

#subfolders_locked=(value) ⇒ Object



265
266
267
# File 'lib/files.com/models/folder.rb', line 265

def subfolders_locked=(value)
  @attributes[:subfolders_locked?] = value
end

#subfolders_locked?Boolean

boolean - Are subfolders locked and unable to be modified?

Returns:

  • (Boolean)


261
262
263
# File 'lib/files.com/models/folder.rb', line 261

def subfolders_locked?
  @attributes[:subfolders_locked?]
end

#tellObject



144
145
146
# File 'lib/files.com/models/folder.rb', line 144

def tell
  @pos
end

#to_pathObject



148
149
150
# File 'lib/files.com/models/folder.rb', line 148

def to_path
  path
end

#typeObject

string - Type: ‘directory` or `file`.



180
181
182
# File 'lib/files.com/models/folder.rb', line 180

def type
  @attributes[:type]
end

#type=(value) ⇒ Object



184
185
186
# File 'lib/files.com/models/folder.rb', line 184

def type=(value)
  @attributes[:type] = value
end