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.



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

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



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

def pos
  @pos ||= 0
end

Class Method Details

.[](*_) ⇒ Object



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

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

.chdir(path, &block) ⇒ Object

Raises:

  • (Errno::ENOENT)


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

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



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

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

.chroot(*args) ⇒ Object



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

def self.chroot(*args); end

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

Parameters:

path (required) - string - Path to operate on.
mkdir_parents - boolean - Create parent directories if they do not exist?


354
355
356
357
358
359
360
361
362
# File 'lib/files.com/models/folder.rb', line 354

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

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

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



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

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

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



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

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

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



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

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

.empty?(*_args) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.entries(path) ⇒ Object



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

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

.exist?(*args) ⇒ Boolean

Returns:

  • (Boolean)


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

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

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



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

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

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



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

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

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



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

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

.getwd(*_args) ⇒ Object



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

def self.getwd(*_args)
  pwd
end

.glob(*_) ⇒ Object



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

def self.glob(*_)
  raise NotImplementedError
end

.home(*_args) ⇒ Object



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

def self.home(*_args)
  ""
end

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

Parameters:

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-Next header or the X-Files-Cursor-Prev header.
per_page - int64 - Number of records to show per page.  (Max: 10,000, 1,000 or less is recommended).
path (required) - string - Path to operate on.
filter - string - If specified, will 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?  If set, we will ignore the folder path provided and search the entire site.  This is the same API used by the search bar in the UI.  Search results are a best effort, not real time, and not guaranteed to match every file.  This field should only be used for ad-hoc (human) searching, and not as part of an automated process.
with_previews - boolean - Include file previews?
with_priority_color - boolean - Include file priority color information?


335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/files.com/models/folder.rb', line 335

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

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

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



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

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

.open(*args, &block) ⇒ Object



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

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

.pwd(*_args) ⇒ Object



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

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

.rmdir(path) ⇒ Object



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

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


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

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

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



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

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

Instance Method Details

#close(*args) ⇒ Object



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

def close(*args); end

#contentsObject



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

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.



213
214
215
# File 'lib/files.com/models/folder.rb', line 213

def crc32
  @attributes[:crc32]
end

#crc32=(value) ⇒ Object



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

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

#created_atObject

date-time - File created date/time



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

def created_at
  @attributes[:created_at]
end

#display_nameObject

string - File/Folder display name



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

def display_name
  @attributes[:display_name]
end

#display_name=(value) ⇒ Object



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

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

#download_uriObject

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



276
277
278
# File 'lib/files.com/models/folder.rb', line 276

def download_uri
  @attributes[:download_uri]
end

#download_uri=(value) ⇒ Object



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

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

#each(&block) ⇒ Object



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

def each(&block)
  contents.each { |x| block.call(x) }
end

#filenoObject



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

def fileno
  stats.id
end

#is_lockedObject

boolean - Is this folder locked and unable to be modified?



267
268
269
# File 'lib/files.com/models/folder.rb', line 267

def is_locked
  @attributes[:is_locked]
end

#is_locked=(value) ⇒ Object



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

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

#md5Object

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



222
223
224
# File 'lib/files.com/models/folder.rb', line 222

def md5
  @attributes[:md5]
end

#md5=(value) ⇒ Object



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

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.



231
232
233
# File 'lib/files.com/models/folder.rb', line 231

def mime_type
  @attributes[:mime_type]
end

#mime_type=(value) ⇒ Object



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

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

#mkdir_parentsObject

boolean - Create parent directories if they do not exist?



312
313
314
# File 'lib/files.com/models/folder.rb', line 312

def mkdir_parents
  @attributes[:mkdir_parents]
end

#mkdir_parents=(value) ⇒ Object



316
317
318
# File 'lib/files.com/models/folder.rb', line 316

def mkdir_parents=(value)
  @attributes[:mkdir_parents] = 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.



195
196
197
# File 'lib/files.com/models/folder.rb', line 195

def mtime
  @attributes[:mtime]
end

#mtime=(value) ⇒ Object



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

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.



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

def path
  @attributes[:path]
end

#path=(value) ⇒ Object



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

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

#permissionsObject

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



249
250
251
# File 'lib/files.com/models/folder.rb', line 249

def permissions
  @attributes[:permissions]
end

#permissions=(value) ⇒ Object



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

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

#previewObject

Preview - File preview



303
304
305
# File 'lib/files.com/models/folder.rb', line 303

def preview
  @attributes[:preview]
end

#preview=(value) ⇒ Object



307
308
309
# File 'lib/files.com/models/folder.rb', line 307

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

#preview_idObject

int64 - File preview ID



294
295
296
# File 'lib/files.com/models/folder.rb', line 294

def preview_id
  @attributes[:preview_id]
end

#preview_id=(value) ⇒ Object



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

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

#priority_colorObject

string - Bookmark/priority color of file/folder



285
286
287
# File 'lib/files.com/models/folder.rb', line 285

def priority_color
  @attributes[:priority_color]
end

#priority_color=(value) ⇒ Object



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

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.



204
205
206
# File 'lib/files.com/models/folder.rb', line 204

def provided_mtime
  @attributes[:provided_mtime]
end

#provided_mtime=(value) ⇒ Object



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

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

#read(*_args) ⇒ Object



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

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

#regionObject

string - Region location



240
241
242
# File 'lib/files.com/models/folder.rb', line 240

def region
  @attributes[:region]
end

#region=(value) ⇒ Object



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

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

#rewindObject



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

def rewind
  @pos = 0
end

#saveObject



320
321
322
323
# File 'lib/files.com/models/folder.rb', line 320

def save
  new_obj = Folder.create(path, @attributes, @options)
  @attributes = new_obj.attributes
end

#seek(pos) ⇒ Object



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

def seek(pos)
  @pos = pos
end

#sizeObject

int64 - File/Folder size



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

def size
  @attributes[:size]
end

#size=(value) ⇒ Object



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

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

#statsObject



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

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

#subfolders_locked=(value) ⇒ Object



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

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

#subfolders_locked?Boolean

boolean - Are subfolders locked and unable to be modified?

Returns:

  • (Boolean)


258
259
260
# File 'lib/files.com/models/folder.rb', line 258

def subfolders_locked?
  @attributes[:subfolders_locked?]
end

#tellObject



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

def tell
  @pos
end

#to_pathObject



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

def to_path
  path
end

#typeObject

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



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

def type
  @attributes[:type]
end

#type=(value) ⇒ Object



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

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