Class: Files::File

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ File

Returns a new instance of File.



180
181
182
183
184
185
186
187
188
# File 'lib/files.com/models/file.rb', line 180

def initialize(*args)
  @attributes = (args[0].is_a?(Hash) && args[0]) || {}
  @options = (args[1].is_a?(Hash) && args[1])
  @options ||= (args[2].is_a?(Hash) && args[2]) || {}
  @attributes[:path] = args[0] if args[0].is_a?(String)
  @mode = args[1] || 'r' if args[1].is_a?(String)
  @write_io = StringIO.new
  @bytes_written = 0
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



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

def attributes
  @attributes
end

#lineno(*_args) ⇒ Object



401
402
403
# File 'lib/files.com/models/file.rb', line 401

def lineno(*_args)
  @lineno ||= 0
end

#modeObject (readonly)

Returns the value of attribute mode.



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

def mode
  @mode
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#posObject



423
424
425
# File 'lib/files.com/models/file.rb', line 423

def pos
  @pos ||= 0
end

#syncObject



503
504
505
# File 'lib/files.com/models/file.rb', line 503

def sync
  @sync ||= false
end

Class Method Details

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

Begin file upload

Parameters:

mkdir_parents - boolean - Create parent directories if they do not exist?
part - int64 - Part if uploading a part.
parts - int64 - How many parts to fetch?
ref - string -
restart - int64 - File byte offset to restart from.
size - int64 - Total bytes of file being uploaded (include bytes being retained if appending/restarting).
with_rename - boolean - Allow file rename instead of overwrite?


1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
# File 'lib/files.com/models/file.rb', line 1213

def self.begin_upload(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 InvalidParameterError.new("Bad parameter: part must be an Integer") if params[:part] and !params[:part].is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: parts must be an Integer") if params[:parts] and !params[:parts].is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: ref must be an String") if params[:ref] and !params[:ref].is_a?(String)
  raise InvalidParameterError.new("Bad parameter: restart must be an Integer") if params[:restart] and !params[:restart].is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: size must be an Integer") if params[:size] and !params[:size].is_a?(Integer)
  raise MissingParameterError.new("Parameter missing: path") unless params[:path]

  response, options = Api.send_request("/file_actions/begin_upload/#{params[:path]}", :post, params, options)
  response.data.map do |entity_data|
    FileUploadPart.new(entity_data, options)
  end
end

.binread(name, *args) ⇒ Object



8
9
10
# File 'lib/files.com/models/file.rb', line 8

def self.binread(name, *args)
  new(name).read(*args)
end

.binwrite(name, *args) ⇒ Object



12
13
14
# File 'lib/files.com/models/file.rb', line 12

def self.binwrite(name, *args)
  new(name).write(*args)
end

.chmod(*_args) ⇒ Object



16
17
18
# File 'lib/files.com/models/file.rb', line 16

def self.chmod(*_args)
  raise NotImplementedError
end

.chown(*_args) ⇒ Object



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

def self.chown(*_args)
  raise NotImplementedError
end

.client(options = {}) ⇒ Object



24
25
26
# File 'lib/files.com/models/file.rb', line 24

def self.client(options = {})
  options[:client] || ApiClient.active_client
end

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

Copy file/folder

Parameters:

destination (required) - string - Copy destination path.
structure - boolean - Copy structure only?
overwrite - boolean - Overwrite existing file(s) in the destination?


1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
# File 'lib/files.com/models/file.rb', line 1174

def self.copy(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 InvalidParameterError.new("Bad parameter: destination must be an String") if params[:destination] and !params[:destination].is_a?(String)
  raise MissingParameterError.new("Parameter missing: path") unless params[:path]
  raise MissingParameterError.new("Parameter missing: destination") unless params[:destination]

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

.copy_stream(*_args) ⇒ Object



28
29
30
# File 'lib/files.com/models/file.rb', line 28

def self.copy_stream(*_args)
  raise NotImplementedError
end

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

Parameters:

path (required) - string - Path to operate on.
action - string - The action to perform.  Can be `append`, `attachment`, `end`, `upload`, `put`, or may not exist
etags[etag] (required) - array(string) - etag identifier.
etags[part] (required) - array(int64) - Part number.
length - int64 - Length of file.
mkdir_parents - boolean - Create parent directories if they do not exist?
part - int64 - Part if uploading a part.
parts - int64 - How many parts to fetch?
provided_mtime - string - User provided modification time.
ref - string -
restart - int64 - File byte offset to restart from.
size - int64 - Size of file.
structure - string - If copying folder, copy just the structure?
with_rename - boolean - Allow file rename instead of overwrite?


1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
# File 'lib/files.com/models/file.rb', line 1095

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 InvalidParameterError.new("Bad parameter: action must be an String") if params[:action] and !params[:action].is_a?(String)
  raise InvalidParameterError.new("Bad parameter: length must be an Integer") if params[:length] and !params[:length].is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: part must be an Integer") if params[:part] and !params[:part].is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: parts must be an Integer") if params[:parts] and !params[:parts].is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: provided_mtime must be an String") if params[:provided_mtime] and !params[:provided_mtime].is_a?(String)
  raise InvalidParameterError.new("Bad parameter: ref must be an String") if params[:ref] and !params[:ref].is_a?(String)
  raise InvalidParameterError.new("Bad parameter: restart must be an Integer") if params[:restart] and !params[:restart].is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: size must be an Integer") if params[:size] and !params[:size].is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: structure must be an String") if params[:structure] and !params[:structure].is_a?(String)
  raise MissingParameterError.new("Parameter missing: path") unless params[:path]

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

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

Parameters:

recursive - boolean - If true, will recursively delete folers.  Otherwise, will error on non-empty folders.


1133
1134
1135
1136
1137
1138
1139
1140
1141
# File 'lib/files.com/models/file.rb', line 1133

def self.delete(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]

  Api.send_request("/files/#{params[:path]}", :delete, params, options)
  nil
end

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



1143
1144
1145
1146
# File 'lib/files.com/models/file.rb', line 1143

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

.directory?(path, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/files.com/models/file.rb', line 32

def self.directory?(path, options = {})
  find(path, {}, options).type == "directory"
end

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

Download file

Parameters:

action - string - Can be blank, `redirect` or `stat`.  If set to `stat`, we will return file information but without a download URL, and without logging a download.  If set to `redirect` we will serve a 302 redirect directly to the file.  This is used for integrations with Zapier, and is not recommended for most integrations.
preview_size - string - Request a preview size.  Can be `small` (default), `large`, `xlarge`, or `pdf`.
with_previews - boolean - Include file preview information?
with_priority_color - boolean - Include file priority color information?


1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
# File 'lib/files.com/models/file.rb', line 1068

def self.download(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 InvalidParameterError.new("Bad parameter: action must be an String") if params[:action] and !params[:action].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 MissingParameterError.new("Parameter missing: path") unless params[:path]

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

.download_file(path, local_path = nil) ⇒ Object



36
37
38
39
# File 'lib/files.com/models/file.rb', line 36

def self.download_file(path, local_path = nil)
  local_path ||= File.basename(path)
  new(path).download_file(local_path)
end

.exist?(path, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
45
46
47
48
49
50
# File 'lib/files.com/models/file.rb', line 41

def self.exist?(path, options = {})
  find(path, {}, options)
  true
rescue Error => e
  if e.code == 404
    false
  else
    raise e
  end
end

.exists?(path, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/files.com/models/file.rb', line 52

def self.exists?(path, options = {})
  exist?(path, options)
end

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

Parameters:

path (required) - string - Path to operate on.
preview_size - string - Request a preview size.  Can be `small` (default), `large`, `xlarge`, or `pdf`.
with_previews - boolean - Include file preview information?
with_priority_color - boolean - Include file priority color information?


1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
# File 'lib/files.com/models/file.rb', line 1153

def self.find(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 InvalidParameterError.new("Bad parameter: preview_size must be an String") if params[:preview_size] and !params[:preview_size].is_a?(String)
  raise MissingParameterError.new("Parameter missing: path") unless params[:path]

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

.for_fd(*_args) ⇒ Object



56
57
58
# File 'lib/files.com/models/file.rb', line 56

def self.for_fd(*_args)
  raise NotImplementedError
end

.foreach(name, *args, &block) ⇒ Object



60
61
62
# File 'lib/files.com/models/file.rb', line 60

def self.foreach(name, *args, &block)
  new(name).each(*args, &block)
end

.from_path(path) ⇒ Object



64
65
66
# File 'lib/files.com/models/file.rb', line 64

def self.from_path(path)
  File.find(path)
end

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



1164
1165
1166
# File 'lib/files.com/models/file.rb', line 1164

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

.identical?(path1, path2) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/files.com/models/file.rb', line 68

def self.identical?(path1, path2)
  new(path1).crc32 == new(path2).crc32
end

.lstat(path) ⇒ Object



72
73
74
# File 'lib/files.com/models/file.rb', line 72

def self.lstat(path)
  new(path).stat
end

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

Move file/folder

Parameters:

destination (required) - string - Move destination path.
overwrite - boolean - Overwrite existing file(s) in the destination?


1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
# File 'lib/files.com/models/file.rb', line 1191

def self.move(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 InvalidParameterError.new("Bad parameter: destination must be an String") if params[:destination] and !params[:destination].is_a?(String)
  raise MissingParameterError.new("Parameter missing: path") unless params[:path]
  raise MissingParameterError.new("Parameter missing: destination") unless params[:destination]

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

.mtime(path) ⇒ Object



76
77
78
# File 'lib/files.com/models/file.rb', line 76

def self.mtime(path)
  new(path).mtime
end

.open(path, mode = "r", options = {}, &block) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/files.com/models/file.rb', line 80

def self.open(path, mode = "r", options = {}, &block)
  file = new(path, mode, options)
  if block
    yield file
    file.close
  end
  file
end

.owned?(_path) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



89
90
91
# File 'lib/files.com/models/file.rb', line 89

def self.owned?(_path)
  raise NotImplementedError
end

.pipe(*_args) ⇒ Object



93
94
95
# File 'lib/files.com/models/file.rb', line 93

def self.pipe(*_args)
  raise NotImplementedError
end

.popen(*_args) ⇒ Object



97
98
99
# File 'lib/files.com/models/file.rb', line 97

def self.popen(*_args)
  raise NotImplementedError
end

.read(name, *args) ⇒ Object



101
102
103
# File 'lib/files.com/models/file.rb', line 101

def self.read(name, *args)
  new(name).read(*args)
end

.readable?(path) ⇒ Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/files.com/models/file.rb', line 105

def self.readable?(path)
  new(path).stat.permissions.include?("read")
end

.readlines(name, *args) ⇒ Object



109
110
111
# File 'lib/files.com/models/file.rb', line 109

def self.readlines(name, *args)
  new(name).readlines(*args)
end

.rename(old_path, new_path) ⇒ Object



113
114
115
# File 'lib/files.com/models/file.rb', line 113

def self.rename(old_path, new_path)
  FileAction.move(old_path, destination: new_path)
end

.select(*_args) ⇒ Object



117
118
119
# File 'lib/files.com/models/file.rb', line 117

def self.select(*_args)
  raise NotImplementedError
end

.stat(path) ⇒ Object



121
122
123
# File 'lib/files.com/models/file.rb', line 121

def self.stat(path)
  new(path).stat
end

.sysopen(*_args) ⇒ Object



125
126
127
# File 'lib/files.com/models/file.rb', line 125

def self.sysopen(*_args)
  raise NotImplementedError
end

.try_convert(*_args) ⇒ Object



129
130
131
# File 'lib/files.com/models/file.rb', line 129

def self.try_convert(*_args)
  raise NotImplementedError
end


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

def self.unlink(*paths)
  paths.map { |p| delete(p) }
end

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

Parameters:

custom_metadata - object - Custom metadata map of keys and values. Limited to 32 keys, 256 characters per key and 1024 characters per value.
provided_mtime - string - Modified time of file.
priority_color - string - Priority/Bookmark color of file.


1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
# File 'lib/files.com/models/file.rb', line 1118

def self.update(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 InvalidParameterError.new("Bad parameter: custom_metadata must be an Hash") if params[:custom_metadata] and !params[:custom_metadata].is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: provided_mtime must be an String") if params[:provided_mtime] and !params[:provided_mtime].is_a?(String)
  raise InvalidParameterError.new("Bad parameter: priority_color must be an String") if params[:priority_color] and !params[:priority_color].is_a?(String)
  raise MissingParameterError.new("Parameter missing: path") unless params[:path]

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

.upload_chunks(io, path, options, upload = nil, etags = [], params: {}) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/files.com/models/file.rb', line 137

def self.upload_chunks(io, path, options, upload = nil, etags = [], params: {})
  etags ||= []
  bytes_written = 0
  request_parts = options[:size] && options[:size] < 5.megabytes ? 1 : 5
  loop do
    begin_upload = File.begin_upload(path, params.merge(ref: upload&.ref, parts: request_parts, part: (upload&.part_number || 0) + 1), options) if begin_upload.nil? || begin_upload.empty?
    upload = begin_upload.is_a?(Enumerable) ? begin_upload.shift : begin_upload
    buf = io.read(upload.partsize) || ""
    bytes_written += buf.length
    method = upload.http_method.downcase.to_sym
    response = client(options).remote_request(method, upload.upload_uri, { 'Content-Length': buf.length.to_s, 'Content-Type': 'application/octet-stream' }, buf)
    etags << { etag: response.headers["ETag"], part: upload.part_number }
    return upload, etags, bytes_written if io.eof?
  end
end

.upload_file(path, destination = nil, options = {}, params: {}) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/files.com/models/file.rb', line 153

def self.upload_file(path, destination = nil, options = {}, params: {})
  local_file = ::File.open(path, 'r')
  destination ||= File.basename(path)
  params[:size] ||= local_file.size
  upload, etags = upload_chunks(local_file, destination, options, params: params)

  params = {
    action: "end",
    etags: etags,
    provided_mtime: local_file.mtime.to_s,
    ref: upload.ref,
    size: local_file.size
  }

  create(destination, params, options)
ensure
  local_file.close
end

.write(*_args) ⇒ Object



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

def self.write(*_args)
  raise NotImplementedError
end

.zero?(path) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.zero?(path)
  new(path).empty?
end

Instance Method Details

#actionObject

string - The action to perform. Can be ‘append`, `attachment`, `end`, `upload`, `put`, or may not exist



863
864
865
# File 'lib/files.com/models/file.rb', line 863

def action
  @attributes[:action]
end

#action=(value) ⇒ Object



867
868
869
# File 'lib/files.com/models/file.rb', line 867

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

#advise(*_args) ⇒ Object



190
# File 'lib/files.com/models/file.rb', line 190

def advise(*_args); end

#atimeObject



192
193
194
# File 'lib/files.com/models/file.rb', line 192

def atime
  mtime
end

#autoclose=(*_args) ⇒ Object



196
# File 'lib/files.com/models/file.rb', line 196

def autoclose=(*_args); end

#autoclose?(*_args) ⇒ Boolean

Returns:

  • (Boolean)


198
# File 'lib/files.com/models/file.rb', line 198

def autoclose?(*_args); end

#begin_upload(params = {}) ⇒ Object

Begin file upload

Parameters:

mkdir_parents - boolean - Create parent directories if they do not exist?
part - int64 - Part if uploading a part.
parts - int64 - How many parts to fetch?
ref - string -
restart - int64 - File byte offset to restart from.
size - int64 - Total bytes of file being uploaded (include bytes being retained if appending/restarting).
with_rename - boolean - Allow file rename instead of overwrite?


1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
# File 'lib/files.com/models/file.rb', line 1040

def begin_upload(params = {})
  params ||= {}
  params[:path] = @attributes[:path]
  raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path]
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String)
  raise InvalidParameterError.new("Bad parameter: part must be an Integer") if params[:part] and !params[:part].is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: parts must be an Integer") if params[:parts] and !params[:parts].is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: ref must be an String") if params[:ref] and !params[:ref].is_a?(String)
  raise InvalidParameterError.new("Bad parameter: restart must be an Integer") if params[:restart] and !params[:restart].is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: size must be an Integer") if params[:size] and !params[:size].is_a?(Integer)
  raise MissingParameterError.new("Parameter missing: path") unless params[:path]

  Api.send_request("/file_actions/begin_upload/#{@attributes[:path]}", :post, params, @options)
end

#binmodeObject



200
201
202
# File 'lib/files.com/models/file.rb', line 200

def binmode
  binmode?
end

#binmode?Boolean

Returns:

  • (Boolean)


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

def binmode?
  true
end

#birthtimeObject



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

def birthtime
  raise NotImplementedError
end

#bytesObject



212
213
214
# File 'lib/files.com/models/file.rb', line 212

def bytes
  read_io.bytes
end

#charsObject



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

def chars
  read_io.chars
end

#chmod(*_args) ⇒ Object



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

def chmod(*_args)
  raise NotImplementedError
end

#chown(*_args) ⇒ Object



224
225
226
# File 'lib/files.com/models/file.rb', line 224

def chown(*_args)
  raise NotImplementedError
end

#clientObject



228
229
230
# File 'lib/files.com/models/file.rb', line 228

def client
  options[:client] || ApiClient.active_client
end

#close(**kwargs) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/files.com/models/file.rb', line 232

def close(**kwargs)
  flush

  if @upload
    end_options = {
      action: 'end',
      etags: @etags,
      provided_mtime: Time.now.to_s,
      ref: @upload.ref,
      size: @bytes_written,
    }
    end_options.merge!(kwargs) if kwargs

    file = File.create(path, end_options, @options)
    @attributes = file.attributes
    @upload = nil
  end
  @write_io.close
end

#close_on_exec=(*args) ⇒ Object



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

def close_on_exec=(*args)
  @write_io.close_on_exec = *args
end

#close_on_exec?(*args) ⇒ Boolean

Returns:

  • (Boolean)


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

def close_on_exec?(*args)
  @write_io.close_on_exec? *args
end

#close_read(*args) ⇒ Object



260
261
262
# File 'lib/files.com/models/file.rb', line 260

def close_read(*args)
  @write_io.close_read *args
end

#close_write(*args) ⇒ Object



264
265
266
# File 'lib/files.com/models/file.rb', line 264

def close_write(*args)
  @write_io.close_write *args
end

#closed?(*args) ⇒ Boolean

Returns:

  • (Boolean)


268
269
270
# File 'lib/files.com/models/file.rb', line 268

def closed?(*args)
  @write_io.closed? *args
end

#codepoints(*args, &block) ⇒ Object



272
273
274
# File 'lib/files.com/models/file.rb', line 272

def codepoints(*args, &block)
  @write_io.codepoints *args, &block
end

#copy(params = {}) ⇒ Object

Copy file/folder

Parameters:

destination (required) - string - Copy destination path.
structure - boolean - Copy structure only?
overwrite - boolean - Overwrite existing file(s) in the destination?


1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
# File 'lib/files.com/models/file.rb', line 1001

def copy(params = {})
  params ||= {}
  params[:path] = @attributes[:path]
  raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path]
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String)
  raise InvalidParameterError.new("Bad parameter: destination must be an String") if params[:destination] and !params[:destination].is_a?(String)
  raise MissingParameterError.new("Parameter missing: path") unless params[:path]
  raise MissingParameterError.new("Parameter missing: destination") unless params[:destination]

  Api.send_request("/file_actions/copy/#{@attributes[:path]}", :post, params, @options)
end

#crc32Object

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



764
765
766
# File 'lib/files.com/models/file.rb', line 764

def crc32
  @attributes[:crc32]
end

#crc32=(value) ⇒ Object



768
769
770
# File 'lib/files.com/models/file.rb', line 768

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

#created_atObject

date-time - File created date/time



687
688
689
# File 'lib/files.com/models/file.rb', line 687

def created_at
  @attributes[:created_at]
end

#created_by_api_key_idObject

int64 - ID of the API key that created the file/folder



588
589
590
# File 'lib/files.com/models/file.rb', line 588

def created_by_api_key_id
  @attributes[:created_by_api_key_id]
end

#created_by_api_key_id=(value) ⇒ Object



592
593
594
# File 'lib/files.com/models/file.rb', line 592

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

#created_by_as2_incoming_message_idObject

int64 - ID of the AS2 Incoming Message that created the file/folder



597
598
599
# File 'lib/files.com/models/file.rb', line 597

def created_by_as2_incoming_message_id
  @attributes[:created_by_as2_incoming_message_id]
end

#created_by_as2_incoming_message_id=(value) ⇒ Object



601
602
603
# File 'lib/files.com/models/file.rb', line 601

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

#created_by_automation_idObject

int64 - ID of the Automation that created the file/folder



606
607
608
# File 'lib/files.com/models/file.rb', line 606

def created_by_automation_id
  @attributes[:created_by_automation_id]
end

#created_by_automation_id=(value) ⇒ Object



610
611
612
# File 'lib/files.com/models/file.rb', line 610

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

#created_by_bundle_registration_idObject

int64 - ID of the Bundle Registration that created the file/folder



615
616
617
# File 'lib/files.com/models/file.rb', line 615

def created_by_bundle_registration_id
  @attributes[:created_by_bundle_registration_id]
end

#created_by_bundle_registration_id=(value) ⇒ Object



619
620
621
# File 'lib/files.com/models/file.rb', line 619

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

#created_by_idObject

int64 - User ID of the User who created the file/folder



579
580
581
# File 'lib/files.com/models/file.rb', line 579

def created_by_id
  @attributes[:created_by_id]
end

#created_by_id=(value) ⇒ Object



583
584
585
# File 'lib/files.com/models/file.rb', line 583

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

#created_by_inbox_idObject

int64 - ID of the Inbox that created the file/folder



624
625
626
# File 'lib/files.com/models/file.rb', line 624

def created_by_inbox_id
  @attributes[:created_by_inbox_id]
end

#created_by_inbox_id=(value) ⇒ Object



628
629
630
# File 'lib/files.com/models/file.rb', line 628

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

#created_by_remote_server_idObject

int64 - ID of the Remote Server that created the file/folder



633
634
635
# File 'lib/files.com/models/file.rb', line 633

def created_by_remote_server_id
  @attributes[:created_by_remote_server_id]
end

#created_by_remote_server_id=(value) ⇒ Object



637
638
639
# File 'lib/files.com/models/file.rb', line 637

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

#created_by_remote_server_sync_idObject

int64 - ID of the Remote Server Sync that created the file/folder



642
643
644
# File 'lib/files.com/models/file.rb', line 642

def created_by_remote_server_sync_id
  @attributes[:created_by_remote_server_sync_id]
end

#created_by_remote_server_sync_id=(value) ⇒ Object



646
647
648
# File 'lib/files.com/models/file.rb', line 646

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

#ctime(*_args) ⇒ Object



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

def ctime(*_args)
  mtime
end

#custom_metadataObject

object - Custom metadata map of keys and values. Limited to 32 keys, 256 characters per key and 1024 characters per value.



651
652
653
# File 'lib/files.com/models/file.rb', line 651

def 
  @attributes[:custom_metadata]
end

#custom_metadata=(value) ⇒ Object



655
656
657
# File 'lib/files.com/models/file.rb', line 655

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

#delete(params = {}) ⇒ Object

Parameters:

recursive - boolean - If true, will recursively delete folers.  Otherwise, will error on non-empty folders.


980
981
982
983
984
985
986
987
988
# File 'lib/files.com/models/file.rb', line 980

def delete(params = {})
  params ||= {}
  params[:path] = @attributes[:path]
  raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[: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]

  Api.send_request("/files/#{@attributes[:path]}", :delete, params, @options)
end

#destroy(params = {}) ⇒ Object



990
991
992
993
# File 'lib/files.com/models/file.rb', line 990

def destroy(params = {})
  delete(params)
  nil
end

#display_nameObject

string - File/Folder display name



660
661
662
# File 'lib/files.com/models/file.rb', line 660

def display_name
  @attributes[:display_name]
end

#display_name=(value) ⇒ Object



664
665
666
# File 'lib/files.com/models/file.rb', line 664

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

#download(params = {}) ⇒ Object

Download file

Parameters:

action - string - Can be blank, `redirect` or `stat`.  If set to `stat`, we will return file information but without a download URL, and without logging a download.  If set to `redirect` we will serve a 302 redirect directly to the file.  This is used for integrations with Zapier, and is not recommended for most integrations.
preview_size - string - Request a preview size.  Can be `small` (default), `large`, `xlarge`, or `pdf`.
with_previews - boolean - Include file preview information?
with_priority_color - boolean - Include file priority color information?


950
951
952
953
954
955
956
957
958
959
960
# File 'lib/files.com/models/file.rb', line 950

def download(params = {})
  params ||= {}
  params[:path] = @attributes[:path]
  raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path]
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String)
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params[:action] and !params[:action].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 MissingParameterError.new("Parameter missing: path") unless params[:path]

  Api.send_request("/files/#{@attributes[:path]}", :get, params, @options)
end

#download_content(io, range: []) ⇒ Object



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

def download_content(io, range: [])
  Files::ApiClient.download_client.stream_download(download_uri_with_load, io, range)
end

#download_file(output_file) ⇒ Object



288
289
290
291
292
# File 'lib/files.com/models/file.rb', line 288

def download_file(output_file)
  ::File.open(output_file, 'wb') do |file|
    download_content(file)
  end
end

#download_uriObject

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



827
828
829
# File 'lib/files.com/models/file.rb', line 827

def download_uri
  @attributes[:download_uri]
end

#download_uri=(value) ⇒ Object



831
832
833
# File 'lib/files.com/models/file.rb', line 831

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

#download_uri_with_loadObject



280
281
282
283
284
285
286
# File 'lib/files.com/models/file.rb', line 280

def download_uri_with_load
  return download_uri if download_uri

  file = File.download(path, {}, @options)
  @attributes = file.attributes
  download_uri
end

#each(*args, &block) ⇒ Object



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

def each(*args, &block)
  read_io.each *args, &block
end

#each_byte(*args, &block) ⇒ Object



302
303
304
# File 'lib/files.com/models/file.rb', line 302

def each_byte(*args, &block)
  read_io.each_byte *args, &block
end

#each_char(*args, &block) ⇒ Object



306
307
308
# File 'lib/files.com/models/file.rb', line 306

def each_char(*args, &block)
  read_io.each_char *args, &block
end

#each_codepoint(*args, &block) ⇒ Object



310
311
312
# File 'lib/files.com/models/file.rb', line 310

def each_codepoint(*args, &block)
  read_io.each_codepoint *args, &block
end

#each_line(*args, &block) ⇒ Object



314
315
316
# File 'lib/files.com/models/file.rb', line 314

def each_line(*args, &block)
  each(*args, &block)
end

#empty?Boolean

Returns:

  • (Boolean)


318
319
320
# File 'lib/files.com/models/file.rb', line 318

def empty?
  size == 0
end

#eofObject



322
323
324
# File 'lib/files.com/models/file.rb', line 322

def eof
  eof?
end

#eof?Boolean

Returns:

  • (Boolean)


326
327
328
# File 'lib/files.com/models/file.rb', line 326

def eof?
  @write_io.eof?
end

#external_encoding(*args) ⇒ Object



330
331
332
# File 'lib/files.com/models/file.rb', line 330

def external_encoding(*args)
  internal_encoding *args
end

#fcntl(*_args) ⇒ Object



334
335
336
# File 'lib/files.com/models/file.rb', line 334

def fcntl(*_args)
  raise NotImplementedError
end

#fdatasync(*_args) ⇒ Object



338
339
340
# File 'lib/files.com/models/file.rb', line 338

def fdatasync(*_args)
  flush
end

#fileno(*_args) ⇒ Object



342
343
344
# File 'lib/files.com/models/file.rb', line 342

def fileno(*_args)
  id
end

#flock(*_args) ⇒ Object



346
347
348
# File 'lib/files.com/models/file.rb', line 346

def flock(*_args)
  raise NotImplementedError
end

#flush(*_args) ⇒ Object



350
351
352
353
354
355
356
357
358
359
# File 'lib/files.com/models/file.rb', line 350

def flush(*_args)
  if mode.include? "w"
    @write_io.rewind if @write_io.is_a?(StringIO)

    @upload, @etags, bytes_written = File.upload_chunks(@write_io, path, options, @upload, @etags, params: @attributes)
    @bytes_written += bytes_written
  elsif mode.include? "a"
    raise NotImplementedError
  end
end

#fsync(*args) ⇒ Object



361
362
363
# File 'lib/files.com/models/file.rb', line 361

def fsync(*args)
  flush *args
end

#getbyte(*args) ⇒ Object



365
366
367
# File 'lib/files.com/models/file.rb', line 365

def getbyte(*args)
  read_io.getbyte *args
end

#getc(*args) ⇒ Object



369
370
371
# File 'lib/files.com/models/file.rb', line 369

def getc(*args)
  read_io.getc *args
end

#gets(*args) ⇒ Object



373
374
375
# File 'lib/files.com/models/file.rb', line 373

def gets(*args)
  read_io.gets *args
end

#internal_encoding(*_args) ⇒ Object



389
390
391
# File 'lib/files.com/models/file.rb', line 389

def internal_encoding(*_args)
  "".encoding
end

#ioctl(*_args) ⇒ Object



393
394
395
# File 'lib/files.com/models/file.rb', line 393

def ioctl(*_args)
  raise NotImplementedError
end

#is_lockedObject

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



818
819
820
# File 'lib/files.com/models/file.rb', line 818

def is_locked
  @attributes[:is_locked]
end

#is_locked=(value) ⇒ Object



822
823
824
# File 'lib/files.com/models/file.rb', line 822

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

#isatty(*_args) ⇒ Object



397
398
399
# File 'lib/files.com/models/file.rb', line 397

def isatty(*_args)
  false
end

#last_modified_by_api_key_idObject

int64 - ID of the API key that last modified the file/folder



701
702
703
# File 'lib/files.com/models/file.rb', line 701

def last_modified_by_api_key_id
  @attributes[:last_modified_by_api_key_id]
end

#last_modified_by_api_key_id=(value) ⇒ Object



705
706
707
# File 'lib/files.com/models/file.rb', line 705

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

#last_modified_by_automation_idObject

int64 - ID of the Automation that last modified the file/folder



710
711
712
# File 'lib/files.com/models/file.rb', line 710

def last_modified_by_automation_id
  @attributes[:last_modified_by_automation_id]
end

#last_modified_by_automation_id=(value) ⇒ Object



714
715
716
# File 'lib/files.com/models/file.rb', line 714

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

#last_modified_by_bundle_registration_idObject

int64 - ID of the Bundle Registration that last modified the file/folder



719
720
721
# File 'lib/files.com/models/file.rb', line 719

def last_modified_by_bundle_registration_id
  @attributes[:last_modified_by_bundle_registration_id]
end

#last_modified_by_bundle_registration_id=(value) ⇒ Object



723
724
725
# File 'lib/files.com/models/file.rb', line 723

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

#last_modified_by_idObject

int64 - User ID of the User who last modified the file/folder



692
693
694
# File 'lib/files.com/models/file.rb', line 692

def last_modified_by_id
  @attributes[:last_modified_by_id]
end

#last_modified_by_id=(value) ⇒ Object



696
697
698
# File 'lib/files.com/models/file.rb', line 696

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

#last_modified_by_remote_server_idObject

int64 - ID of the Remote Server that last modified the file/folder



728
729
730
# File 'lib/files.com/models/file.rb', line 728

def last_modified_by_remote_server_id
  @attributes[:last_modified_by_remote_server_id]
end

#last_modified_by_remote_server_id=(value) ⇒ Object



732
733
734
# File 'lib/files.com/models/file.rb', line 732

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

#last_modified_by_remote_server_sync_idObject

int64 - ID of the Remote Server Sync that last modified the file/folder



737
738
739
# File 'lib/files.com/models/file.rb', line 737

def last_modified_by_remote_server_sync_id
  @attributes[:last_modified_by_remote_server_sync_id]
end

#last_modified_by_remote_server_sync_id=(value) ⇒ Object



741
742
743
# File 'lib/files.com/models/file.rb', line 741

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

#lengthObject

int64 - Length of file.



872
873
874
# File 'lib/files.com/models/file.rb', line 872

def length
  @attributes[:length]
end

#length=(value) ⇒ Object



876
877
878
# File 'lib/files.com/models/file.rb', line 876

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

#lines(*args, &block) ⇒ Object



407
408
409
# File 'lib/files.com/models/file.rb', line 407

def lines(*args, &block)
  each_line *args, &block
end

#lstat(*_args) ⇒ Object



411
412
413
# File 'lib/files.com/models/file.rb', line 411

def lstat(*_args)
  stats
end

#md5Object

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



773
774
775
# File 'lib/files.com/models/file.rb', line 773

def md5
  @attributes[:md5]
end

#md5=(value) ⇒ Object



777
778
779
# File 'lib/files.com/models/file.rb', line 777

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.



782
783
784
# File 'lib/files.com/models/file.rb', line 782

def mime_type
  @attributes[:mime_type]
end

#mime_type=(value) ⇒ Object



786
787
788
# File 'lib/files.com/models/file.rb', line 786

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

#mkdir_parentsObject

boolean - Create parent directories if they do not exist?



881
882
883
# File 'lib/files.com/models/file.rb', line 881

def mkdir_parents
  @attributes[:mkdir_parents]
end

#mkdir_parents=(value) ⇒ Object



885
886
887
# File 'lib/files.com/models/file.rb', line 885

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

#move(params = {}) ⇒ Object

Move file/folder

Parameters:

destination (required) - string - Move destination path.
overwrite - boolean - Overwrite existing file(s) in the destination?


1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
# File 'lib/files.com/models/file.rb', line 1018

def move(params = {})
  params ||= {}
  params[:path] = @attributes[:path]
  raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path]
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String)
  raise InvalidParameterError.new("Bad parameter: destination must be an String") if params[:destination] and !params[:destination].is_a?(String)
  raise MissingParameterError.new("Parameter missing: path") unless params[:path]
  raise MissingParameterError.new("Parameter missing: destination") unless params[:destination]

  Api.send_request("/file_actions/move/#{@attributes[:path]}", :post, params, @options)
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.



746
747
748
# File 'lib/files.com/models/file.rb', line 746

def mtime
  @attributes[:mtime]
end

#mtime=(value) ⇒ Object



750
751
752
# File 'lib/files.com/models/file.rb', line 750

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

#mv(destination) ⇒ Object



415
416
417
# File 'lib/files.com/models/file.rb', line 415

def mv(destination)
  File.move(path, destination)
end

#partObject

int64 - Part if uploading a part.



890
891
892
# File 'lib/files.com/models/file.rb', line 890

def part
  @attributes[:part]
end

#part=(value) ⇒ Object



894
895
896
# File 'lib/files.com/models/file.rb', line 894

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

#partsObject

int64 - How many parts to fetch?



899
900
901
# File 'lib/files.com/models/file.rb', line 899

def parts
  @attributes[:parts]
end

#parts=(value) ⇒ Object



903
904
905
# File 'lib/files.com/models/file.rb', line 903

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



570
571
572
# File 'lib/files.com/models/file.rb', line 570

def path
  @attributes[:path]
end

#path=(value) ⇒ Object



574
575
576
# File 'lib/files.com/models/file.rb', line 574

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

#permissionsObject

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



800
801
802
# File 'lib/files.com/models/file.rb', line 800

def permissions
  @attributes[:permissions]
end

#permissions=(value) ⇒ Object



804
805
806
# File 'lib/files.com/models/file.rb', line 804

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

#pid(*_args) ⇒ Object



419
420
421
# File 'lib/files.com/models/file.rb', line 419

def pid(*_args)
  Process.pid
end

#pread(*args) ⇒ Object



427
428
429
# File 'lib/files.com/models/file.rb', line 427

def pread(*args)
  read_io.pread *args
end

#previewObject

Preview - File preview



854
855
856
# File 'lib/files.com/models/file.rb', line 854

def preview
  @attributes[:preview]
end

#preview=(value) ⇒ Object



858
859
860
# File 'lib/files.com/models/file.rb', line 858

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

#preview_idObject

int64 - File preview ID



845
846
847
# File 'lib/files.com/models/file.rb', line 845

def preview_id
  @attributes[:preview_id]
end

#preview_id=(value) ⇒ Object



849
850
851
# File 'lib/files.com/models/file.rb', line 849

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


431
432
433
# File 'lib/files.com/models/file.rb', line 431

def print(*args)
  @write_io.print *args
end

#printf(*args) ⇒ Object



435
436
437
# File 'lib/files.com/models/file.rb', line 435

def printf(*args)
  @write_io.printf *args
end

#priority_colorObject

string - Bookmark/priority color of file/folder



836
837
838
# File 'lib/files.com/models/file.rb', line 836

def priority_color
  @attributes[:priority_color]
end

#priority_color=(value) ⇒ Object



840
841
842
# File 'lib/files.com/models/file.rb', line 840

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.



755
756
757
# File 'lib/files.com/models/file.rb', line 755

def provided_mtime
  @attributes[:provided_mtime]
end

#provided_mtime=(value) ⇒ Object



759
760
761
# File 'lib/files.com/models/file.rb', line 759

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

#putc(*args) ⇒ Object



439
440
441
# File 'lib/files.com/models/file.rb', line 439

def putc(*args)
  @write_io.putc *args
end

#puts(*args) ⇒ Object



443
444
445
# File 'lib/files.com/models/file.rb', line 443

def puts(*args)
  @write_io.puts *args
end

#pwrite(*args) ⇒ Object



447
448
449
# File 'lib/files.com/models/file.rb', line 447

def pwrite(*args)
  @write_io.pwrite *args
end

#read(*args) ⇒ Object



451
452
453
# File 'lib/files.com/models/file.rb', line 451

def read(*args)
  read_io.read *args
end

#read_io(**options) ⇒ Object



377
378
379
380
381
382
383
384
385
386
387
# File 'lib/files.com/models/file.rb', line 377

def read_io(**options)
  @read_io ||= begin
    r, w = SizableIO.pipe
    Thread.new do
      download_content(w, **options)
    ensure
      w.close
    end
    r.wait!(5)
  end
end

#read_nonblock(*args) ⇒ Object



455
456
457
# File 'lib/files.com/models/file.rb', line 455

def read_nonblock(*args)
  read_io.read_nonblock *args
end

#readbyte(*args) ⇒ Object



459
460
461
# File 'lib/files.com/models/file.rb', line 459

def readbyte(*args)
  read_io.readbyte *args
end

#readchar(*args) ⇒ Object



463
464
465
# File 'lib/files.com/models/file.rb', line 463

def readchar(*args)
  read_io.readchar *args
end

#readline(*args) ⇒ Object



467
468
469
# File 'lib/files.com/models/file.rb', line 467

def readline(*args)
  read_io.readline *args
end

#readlines(*args) ⇒ Object



471
472
473
# File 'lib/files.com/models/file.rb', line 471

def readlines(*args)
  io.readlines(*args)
end

#readpartial(*args) ⇒ Object



475
476
477
# File 'lib/files.com/models/file.rb', line 475

def readpartial(*args)
  read_io.readpartial *args
end

#refObject

string -



908
909
910
# File 'lib/files.com/models/file.rb', line 908

def ref
  @attributes[:ref]
end

#ref=(value) ⇒ Object



912
913
914
# File 'lib/files.com/models/file.rb', line 912

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

#regionObject

string - Region location



791
792
793
# File 'lib/files.com/models/file.rb', line 791

def region
  @attributes[:region]
end

#region=(value) ⇒ Object



795
796
797
# File 'lib/files.com/models/file.rb', line 795

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

#rename(destination) ⇒ Object



479
480
481
# File 'lib/files.com/models/file.rb', line 479

def rename(destination)
  File.rename(path, destination)
end

#reopen(*_args) ⇒ Object



483
484
485
# File 'lib/files.com/models/file.rb', line 483

def reopen(*_args)
  raise NotImplementedError
end

#restartObject

int64 - File byte offset to restart from.



917
918
919
# File 'lib/files.com/models/file.rb', line 917

def restart
  @attributes[:restart]
end

#restart=(value) ⇒ Object



921
922
923
# File 'lib/files.com/models/file.rb', line 921

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

#rewindObject



487
488
489
# File 'lib/files.com/models/file.rb', line 487

def rewind
  @pos = 0
end

#saveObject



1055
1056
1057
1058
1059
# File 'lib/files.com/models/file.rb', line 1055

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

#seek(pos) ⇒ Object



491
492
493
# File 'lib/files.com/models/file.rb', line 491

def seek(pos)
  @pos = pos
end

#set_encoding(*_args) ⇒ Object



495
496
497
# File 'lib/files.com/models/file.rb', line 495

def set_encoding(*_args)
  raise NotImplementedError
end

#sizeObject

int64 - File/Folder size



678
679
680
# File 'lib/files.com/models/file.rb', line 678

def size
  @attributes[:size]
end

#size=(value) ⇒ Object



682
683
684
# File 'lib/files.com/models/file.rb', line 682

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

#stat(*_args) ⇒ Object



499
500
501
# File 'lib/files.com/models/file.rb', line 499

def stat(*_args)
  stats
end

#structureObject

string - If copying folder, copy just the structure?



926
927
928
# File 'lib/files.com/models/file.rb', line 926

def structure
  @attributes[:structure]
end

#structure=(value) ⇒ Object



930
931
932
# File 'lib/files.com/models/file.rb', line 930

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

#subfolders_locked=(value) ⇒ Object



813
814
815
# File 'lib/files.com/models/file.rb', line 813

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

#subfolders_locked?Boolean

boolean - Are subfolders locked and unable to be modified?

Returns:

  • (Boolean)


809
810
811
# File 'lib/files.com/models/file.rb', line 809

def subfolders_locked?
  @attributes[:subfolders_locked?]
end

#sysread(*args) ⇒ Object



507
508
509
# File 'lib/files.com/models/file.rb', line 507

def sysread(*args)
  read *args
end

#sysseek(*args) ⇒ Object



511
512
513
# File 'lib/files.com/models/file.rb', line 511

def sysseek(*args)
  seek *args
end

#syswrite(*_args) ⇒ Object



515
516
517
# File 'lib/files.com/models/file.rb', line 515

def syswrite(*_args)
  raise NotImplementedError
end

#tellObject



519
520
521
# File 'lib/files.com/models/file.rb', line 519

def tell
  pos
end

#to_i(*_args) ⇒ Object



523
524
525
# File 'lib/files.com/models/file.rb', line 523

def to_i(*_args)
  fileno
end

#to_io(*_args) ⇒ Object



527
528
529
# File 'lib/files.com/models/file.rb', line 527

def to_io(*_args)
  @write_io
end

#to_path(*_args) ⇒ Object



531
532
533
# File 'lib/files.com/models/file.rb', line 531

def to_path(*_args)
  path
end

#truncate(*_args) ⇒ Object



535
536
537
# File 'lib/files.com/models/file.rb', line 535

def truncate(*_args)
  raise NotImplementedError
end

#tty?(*_args) ⇒ Boolean

Returns:

  • (Boolean)


539
540
541
# File 'lib/files.com/models/file.rb', line 539

def tty?(*_args)
  false
end

#typeObject

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



669
670
671
# File 'lib/files.com/models/file.rb', line 669

def type
  @attributes[:type]
end

#type=(value) ⇒ Object



673
674
675
# File 'lib/files.com/models/file.rb', line 673

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

#ungetbyte(*_args) ⇒ Object



543
544
545
# File 'lib/files.com/models/file.rb', line 543

def ungetbyte(*_args)
  raise NotImplementedError
end

#ungetc(*_args) ⇒ Object



547
548
549
# File 'lib/files.com/models/file.rb', line 547

def ungetc(*_args)
  raise NotImplementedError
end

#update(params = {}) ⇒ Object

Parameters:

custom_metadata - object - Custom metadata map of keys and values. Limited to 32 keys, 256 characters per key and 1024 characters per value.
provided_mtime - string - Modified time of file.
priority_color - string - Priority/Bookmark color of file.


966
967
968
969
970
971
972
973
974
975
976
# File 'lib/files.com/models/file.rb', line 966

def update(params = {})
  params ||= {}
  params[:path] = @attributes[:path]
  raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path]
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String)
  raise InvalidParameterError.new("Bad parameter: provided_mtime must be an String") if params[:provided_mtime] and !params[:provided_mtime].is_a?(String)
  raise InvalidParameterError.new("Bad parameter: priority_color must be an String") if params[:priority_color] and !params[:priority_color].is_a?(String)
  raise MissingParameterError.new("Parameter missing: path") unless params[:path]

  Api.send_request("/files/#{@attributes[:path]}", :patch, params, @options)
end

#upload_file(local_file) ⇒ Object



551
552
553
# File 'lib/files.com/models/file.rb', line 551

def upload_file(local_file)
  File.upload_file(local_file.path, params: @attributes)
end

#with_renameObject

boolean - Allow file rename instead of overwrite?



935
936
937
# File 'lib/files.com/models/file.rb', line 935

def with_rename
  @attributes[:with_rename]
end

#with_rename=(value) ⇒ Object



939
940
941
# File 'lib/files.com/models/file.rb', line 939

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

#write(*args) ⇒ Object



555
556
557
558
559
560
561
562
563
# File 'lib/files.com/models/file.rb', line 555

def write(*args)
  @mode ||= 'w'
  if args[0].respond_to?(:read)
    flush if @write_io.size > 0 # rubocop:disable Style/ZeroLengthPredicate
    @write_io = args[0]
  else
    @write_io.write *args
  end
end

#write_nonblock(*args) ⇒ Object



565
566
567
# File 'lib/files.com/models/file.rb', line 565

def write_nonblock(*args)
  @write_io.write_nonblock *args
end