files.com 1.1.795 → 1.1.797

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11c9cb5536d9eae379bb5ed007a014c12a743458e057eeef86b2a7334f1edc7c
4
- data.tar.gz: 6dd7da27279f732340fa662aca010d577deae9d2b0de35da14d2610ca184d41e
3
+ metadata.gz: 5ff0801679675d74a77850b8b613be4230e3c652bc649c9b1ad6d1efe45dbcd4
4
+ data.tar.gz: 65880cc3c2ff063f8bd35798fbd1457367e23f9bf300bf86d6c65c02cec87232
5
5
  SHA512:
6
- metadata.gz: f242163c3e01950dde4dcddc118768fe6dae7483c6d1c21e505ff2dd58cd8bba1c6549da0cbd6dd4062c68ba7b614f219cc413b03b90f2c66cc8f4266df8bb2b
7
- data.tar.gz: 366bbb0dcf8ff40afb34f3cf808264c2c3d9fa913062211adb5bd5d536c8abe365519b321cffe1f46f18d74c50d714c3e3efca0f1043effa54a6906a418a7d2a
6
+ metadata.gz: c4a8b61e41f95f29e1bcdf56a236ba4c573e9e2b16e2be235792d36b086423e4a8dad787082714b0ecfade5ebc8534ddfdd8427b7913a9ae9328e771bdd3ee2c
7
+ data.tar.gz: 6f2c9a22034fd46a304facc1b23d297d7b4e4746d02b0a9eeae4396d5043f5b627f51af4973630742c492d3aab1602b3a344f17826e79786da04543130ffe00d
data/_VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.795
1
+ 1.1.797
data/docs/gpg_key.md CHANGED
@@ -56,7 +56,7 @@ Files::GpgKey.list(
56
56
  * `cursor` (string): Used for pagination. When a list request has more records available, cursors are provided in the response headers `X-Files-Cursor-Next` and `X-Files-Cursor-Prev`. Send one of those cursor value here to resume an existing list from the next available record. Note: many of our SDKs have iterator methods that will automatically handle cursor-based pagination.
57
57
  * `per_page` (int64): Number of records to show per page. (Max: 10000, 1,000 or less is recommended).
58
58
  * `sort_by` (object): If set, sort records by the specified field in either `asc` or `desc` direction. Valid fields are `workspace_id`, `name` or `expires_at`.
59
- * `filter` (object): If set, return records where the specified field is equal to the supplied value. Valid fields are `workspace_id`, `partner_id` or `expires_at`. Valid field combinations are `[ workspace_id, expires_at ]`.
59
+ * `filter` (object): If set, return records where the specified field is equal to the supplied value. Valid fields are `workspace_id`, `partner_id` or `expires_at`. Valid field combinations are `[ workspace_id, partner_id ]`, `[ workspace_id, expires_at ]`, `[ partner_id, expires_at ]` or `[ workspace_id, partner_id, expires_at ]`.
60
60
  * `filter_gt` (object): If set, return records where the specified field is greater than the supplied value. Valid fields are `expires_at`.
61
61
  * `filter_gteq` (object): If set, return records where the specified field is greater than or equal the supplied value. Valid fields are `expires_at`.
62
62
  * `filter_lt` (object): If set, return records where the specified field is less than the supplied value. Valid fields are `expires_at`.
@@ -72,9 +72,9 @@ module Files
72
72
  PathUtil.normalize("_", root, id.to_s, relative_path)
73
73
  end
74
74
 
75
- def self.upload_to_remote_server(path, remote_server_id, destination = nil, options = {}, params: {})
75
+ def self.upload_to_remote_server(path, remote_server_id, destination = nil, options = {}, params: {}, progress: nil)
76
76
  destination ||= ::File.basename(path)
77
- upload_file(path, underscore_destination_path("RemoteServers", remote_server_id, destination), options, params: params)
77
+ upload_file(path, underscore_destination_path("RemoteServers", remote_server_id, destination), options, params: params, progress: progress)
78
78
  end
79
79
 
80
80
  def self.copy_to_remote_server(path, remote_server_id, destination, params = {}, options = {})
@@ -85,9 +85,9 @@ module Files
85
85
  move(path, params.merge(destination: underscore_destination_path("RemoteServers", remote_server_id, destination)), options)
86
86
  end
87
87
 
88
- def self.upload_to_snapshot(path, snapshot_id, destination = nil, options = {}, params: {})
88
+ def self.upload_to_snapshot(path, snapshot_id, destination = nil, options = {}, params: {}, progress: nil)
89
89
  destination ||= ::File.basename(path)
90
- upload_file(path, underscore_destination_path("Snapshots", snapshot_id, destination), options, params: params)
90
+ upload_file(path, underscore_destination_path("Snapshots", snapshot_id, destination), options, params: params, progress: progress)
91
91
  end
92
92
 
93
93
  def self.copy_to_snapshot(path, snapshot_id, destination, params = {}, options = {})
@@ -98,9 +98,9 @@ module Files
98
98
  move(path, params.merge(destination: underscore_destination_path("Snapshots", snapshot_id, destination)), options)
99
99
  end
100
100
 
101
- def self.upload_to_child_site(path, site_id, destination = nil, options = {}, params: {})
101
+ def self.upload_to_child_site(path, site_id, destination = nil, options = {}, params: {}, progress: nil)
102
102
  destination ||= ::File.basename(path)
103
- upload_file(path, underscore_destination_path("Sites", site_id, destination), options, params: params)
103
+ upload_file(path, underscore_destination_path("Sites", site_id, destination), options, params: params, progress: progress)
104
104
  end
105
105
 
106
106
  def self.copy_to_child_site(path, site_id, destination, params = {}, options = {})
@@ -207,27 +207,59 @@ module Files
207
207
  paths.map { |p| delete(p) }
208
208
  end
209
209
 
210
- def self.upload_chunks(io, path, options, upload = nil, etags = [], params: {})
210
+ # Uploads what io holds to path, a part at a time as the API grants each, and returns the last part, the parts'
211
+ # ETags and the bytes sent. Each part is filled from as many reads as it takes (read_part). With progress, a
212
+ # callable, each part's response must be a success (2xx) before the part counts as acknowledged; progress is then
213
+ # called with total_bytes (nil: unknown here), acknowledged_bytes (this call's bytes so far), part_number and
214
+ # part_bytes. Anything it raises ends the upload there, with no later part planned or sent.
215
+ def self.upload_chunks(io, path, options, upload = nil, etags = [], params: {}, progress: nil)
211
216
  etags ||= []
212
217
  bytes_written = 0
213
218
  request_parts = options[:size] && options[:size] < 5.megabytes ? 1 : 5
214
219
  loop do
215
220
  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?
216
221
  upload = begin_upload.is_a?(Enumerable) ? begin_upload.shift : begin_upload
217
- buf = io.read(upload.partsize) || ""
222
+ buf = read_part(io, upload.partsize)
218
223
  bytes_written += buf.length
219
224
  method = upload.http_method.downcase.to_sym
220
225
  response = client(options).remote_request(method, upload.upload_uri, { 'Content-Length': buf.length.to_s, 'Content-Type': 'application/octet-stream' }, buf)
226
+ raise APIError.new("Transfer request failed", http_status: response.status), cause: nil if progress && !response.status.between?(200, 299)
227
+
221
228
  etags << { etag: response.headers["ETag"], part: upload.part_number }
229
+ progress&.call({ total_bytes: nil, acknowledged_bytes: bytes_written, part_number: upload.part_number, part_bytes: buf.length })
222
230
  return upload, etags, bytes_written if io.eof?
223
231
  end
224
232
  end
225
233
 
226
- def self.upload_file(path, destination = nil, options = {}, params: {})
234
+ # The next part's bytes from io: as many reads as it takes to fill length bytes. A read that gives nothing (nil or
235
+ # "") ends the part when io.eof? says the source has ended; before its end, the source made no progress, and the
236
+ # part is not sent.
237
+ private_class_method def self.read_part(io, length)
238
+ buf = String.new(encoding: Encoding::BINARY)
239
+ while buf.bytesize < length
240
+ chunk = io.read(length - buf.bytesize)
241
+ if chunk.nil? || chunk.empty?
242
+ break if io.eof?
243
+
244
+ raise InvalidParameterError, "The upload source returned no bytes before its end"
245
+ end
246
+ # A read that fills the part at once, as an IO's or a StringIO's does, is sent as it came.
247
+ return chunk if buf.empty? && chunk.bytesize == length
248
+
249
+ buf << chunk.b
250
+ end
251
+ buf
252
+ end
253
+
254
+ # With progress, a callable, it is called after each part is acknowledged, as upload_chunks reports it, with
255
+ # total_bytes the local file's size.
256
+ def self.upload_file(path, destination = nil, options = {}, params: {}, progress: nil)
227
257
  local_file = ::File.open(path, 'r')
228
258
  destination ||= File.basename(path)
229
259
  params[:size] ||= local_file.size
230
- upload, etags = upload_chunks(local_file, destination, options, params: params)
260
+ total_bytes = local_file.size
261
+ report = progress && ->(part) { progress.call(part.merge(total_bytes: total_bytes)) }
262
+ upload, etags = upload_chunks(local_file, destination, options, params: params, progress: report)
231
263
 
232
264
  params = {
233
265
  action: "end",
@@ -242,7 +242,7 @@ module Files
242
242
  # cursor - string - Used for pagination. When a list request has more records available, cursors are provided in the response headers `X-Files-Cursor-Next` and `X-Files-Cursor-Prev`. Send one of those cursor value here to resume an existing list from the next available record. Note: many of our SDKs have iterator methods that will automatically handle cursor-based pagination.
243
243
  # per_page - int64 - Number of records to show per page. (Max: 10000, 1,000 or less is recommended).
244
244
  # sort_by - object - If set, sort records by the specified field in either `asc` or `desc` direction. Valid fields are `workspace_id`, `name` or `expires_at`.
245
- # filter - object - If set, return records where the specified field is equal to the supplied value. Valid fields are `workspace_id`, `partner_id` or `expires_at`. Valid field combinations are `[ workspace_id, expires_at ]`.
245
+ # filter - object - If set, return records where the specified field is equal to the supplied value. Valid fields are `workspace_id`, `partner_id` or `expires_at`. Valid field combinations are `[ workspace_id, partner_id ]`, `[ workspace_id, expires_at ]`, `[ partner_id, expires_at ]` or `[ workspace_id, partner_id, expires_at ]`.
246
246
  # filter_gt - object - If set, return records where the specified field is greater than the supplied value. Valid fields are `expires_at`.
247
247
  # filter_gteq - object - If set, return records where the specified field is greater than or equal the supplied value. Valid fields are `expires_at`.
248
248
  # filter_lt - object - If set, return records where the specified field is less than the supplied value. Valid fields are `expires_at`.