google-apis-core 0.11.2 → 0.18.0
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 +4 -4
- data/CHANGELOG.md +67 -0
- data/lib/google/apis/core/base_service.rb +94 -5
- data/lib/google/apis/core/composite_io.rb +1 -1
- data/lib/google/apis/core/download.rb +6 -2
- data/lib/google/apis/core/http_command.rb +15 -4
- data/lib/google/apis/core/multipart.rb +4 -4
- data/lib/google/apis/core/storage_download.rb +1 -1
- data/lib/google/apis/core/storage_upload.rb +92 -3
- data/lib/google/apis/core/version.rb +1 -1
- data/lib/google/apis/errors.rb +5 -1
- data/lib/google/apis/options.rb +2 -1
- metadata +12 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adcaaf904d1c4e3e203b45c527c259c1be63aa675402247297a96ca087b5e14a
|
4
|
+
data.tar.gz: 6bafca376fc6569b0e8ff19071c1729e83310f55d3cb3b99e11d5440448ffd83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a24caabd4a3bfc09f9de6be416165fa6aa4b90f89b7ecf4f948801cba266c81e497f773fe25740a723056db708342a28eb36584a11dc43a436ca90e2eb95234
|
7
|
+
data.tar.gz: 4da89f87e45e5edf5c359aef57878e044c90411638c899744efe5235215fa576b2cd3eb46fa61b1678a4b57dda521b6f9fb386c8868a3b9118ddc494757f8a9a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,72 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 0.18.0 (2025-05-22)
|
4
|
+
|
5
|
+
#### Features
|
6
|
+
|
7
|
+
* Restart & delete resumable upload ([#21896](https://github.com/googleapis/google-api-ruby-client/issues/21896))
|
8
|
+
|
9
|
+
### 0.17.0 (2025-04-30)
|
10
|
+
|
11
|
+
#### Features
|
12
|
+
|
13
|
+
* ruby 3.1 minimum, 3.4 default ([#22594](https://github.com/googleapis/google-api-ruby-client/issues/22594))
|
14
|
+
#### Bug Fixes
|
15
|
+
|
16
|
+
* Fixed a method redefined warning ([#21572](https://github.com/googleapis/google-api-ruby-client/issues/21572))
|
17
|
+
* Ensure compatibility with frozen string literals ([#21648](https://github.com/googleapis/google-api-ruby-client/issues/21648))
|
18
|
+
|
19
|
+
### 0.16.0 (2025-01-12)
|
20
|
+
|
21
|
+
#### Features
|
22
|
+
|
23
|
+
* add ECONNRESET error as retriable error ([#20354](https://github.com/googleapis/google-api-ruby-client/issues/20354))
|
24
|
+
|
25
|
+
### 0.15.1 (2024-07-29)
|
26
|
+
|
27
|
+
#### Bug Fixes
|
28
|
+
|
29
|
+
* remove rexml from dependencies ([#19971](https://github.com/googleapis/google-api-ruby-client/issues/19971))
|
30
|
+
|
31
|
+
### 0.15.0 (2024-05-13)
|
32
|
+
|
33
|
+
#### Features
|
34
|
+
|
35
|
+
* Introduce api_version to discovery clients ([#18969](https://github.com/googleapis/google-api-ruby-client/issues/18969))
|
36
|
+
|
37
|
+
### 0.14.1 (2024-03-13)
|
38
|
+
|
39
|
+
#### Bug Fixes
|
40
|
+
|
41
|
+
* fixes uninitialized Pathname issue ([#18480](https://github.com/googleapis/google-api-ruby-client/issues/18480))
|
42
|
+
|
43
|
+
### 0.14.0 (2024-02-23)
|
44
|
+
|
45
|
+
#### Features
|
46
|
+
|
47
|
+
* Update minimum Ruby version to 2.7 ([#17896](https://github.com/googleapis/google-api-ruby-client/issues/17896))
|
48
|
+
#### Bug Fixes
|
49
|
+
|
50
|
+
* allow BaseService#root_url to be an Addressable::URI ([#17895](https://github.com/googleapis/google-api-ruby-client/issues/17895))
|
51
|
+
|
52
|
+
### 0.13.0 (2024-01-26)
|
53
|
+
|
54
|
+
#### Features
|
55
|
+
|
56
|
+
* Verify credential universe domain against configured universe domain ([#17569](https://github.com/googleapis/google-api-ruby-client/issues/17569))
|
57
|
+
|
58
|
+
### 0.12.0 (2024-01-22)
|
59
|
+
|
60
|
+
#### Features
|
61
|
+
|
62
|
+
* Support for universe_domain ([#17131](https://github.com/googleapis/google-api-ruby-client/issues/17131))
|
63
|
+
|
64
|
+
### 0.11.3 (2024-01-17)
|
65
|
+
|
66
|
+
#### Bug Fixes
|
67
|
+
|
68
|
+
* download with destination as pathname ([#17120](https://github.com/googleapis/google-api-ruby-client/issues/17120))
|
69
|
+
|
3
70
|
### 0.11.2 (2023-10-27)
|
4
71
|
|
5
72
|
#### Bug Fixes
|
@@ -93,11 +93,49 @@ module Google
|
|
93
93
|
# Base service for all APIs. Not to be used directly.
|
94
94
|
#
|
95
95
|
class BaseService
|
96
|
+
##
|
97
|
+
# A substitution string for the universe domain in an endpoint template
|
98
|
+
# @return [String]
|
99
|
+
#
|
100
|
+
ENDPOINT_SUBSTITUTION = "$UNIVERSE_DOMAIN$".freeze
|
101
|
+
|
96
102
|
include Logging
|
97
103
|
|
104
|
+
# Universe domain
|
105
|
+
# @return [String]
|
106
|
+
attr_reader :universe_domain
|
107
|
+
|
108
|
+
# Set the universe domain.
|
109
|
+
# If the root URL was set with a universe domain substitution, it is
|
110
|
+
# updated to reflect the new universe domain.
|
111
|
+
#
|
112
|
+
# @param new_ud [String,nil] The new universe domain, or nil to use the Google Default Universe
|
113
|
+
def universe_domain= new_ud
|
114
|
+
new_ud ||= ENV["GOOGLE_CLOUD_UNIVERSE_DOMAIN"] || "googleapis.com"
|
115
|
+
if @root_url_template
|
116
|
+
@root_url = @root_url_template.gsub ENDPOINT_SUBSTITUTION, new_ud
|
117
|
+
end
|
118
|
+
@universe_domain = new_ud
|
119
|
+
end
|
120
|
+
|
98
121
|
# Root URL (host/port) for the API
|
99
|
-
# @return [Addressable::URI]
|
100
|
-
|
122
|
+
# @return [Addressable::URI, String]
|
123
|
+
attr_reader :root_url
|
124
|
+
|
125
|
+
# Set the root URL.
|
126
|
+
# If the given url includes a universe domain substitution, it is
|
127
|
+
# resolved in the current universe domain
|
128
|
+
#
|
129
|
+
# @param url_or_template [Addressable::URI, String] The URL, which can include a universe domain substitution
|
130
|
+
def root_url= url_or_template
|
131
|
+
if url_or_template.is_a?(String) && url_or_template.include?(ENDPOINT_SUBSTITUTION)
|
132
|
+
@root_url_template = url_or_template
|
133
|
+
@root_url = url_or_template.gsub ENDPOINT_SUBSTITUTION, universe_domain
|
134
|
+
else
|
135
|
+
@root_url_template = nil
|
136
|
+
@root_url = url_or_template
|
137
|
+
end
|
138
|
+
end
|
101
139
|
|
102
140
|
# Additional path prefix for all API methods
|
103
141
|
# @return [Addressable::URI]
|
@@ -113,7 +151,7 @@ module Google
|
|
113
151
|
|
114
152
|
# HTTP client
|
115
153
|
# @return [HTTPClient]
|
116
|
-
|
154
|
+
attr_writer :client
|
117
155
|
|
118
156
|
# General settings
|
119
157
|
# @return [Google::Apis::ClientOptions]
|
@@ -136,7 +174,9 @@ module Google
|
|
136
174
|
# @param [String,Addressable::URI] base_path
|
137
175
|
# Additional path prefix for all API methods
|
138
176
|
# @api private
|
139
|
-
def initialize(root_url, base_path, client_name: nil, client_version: nil)
|
177
|
+
def initialize(root_url, base_path, client_name: nil, client_version: nil, universe_domain: nil)
|
178
|
+
@root_url_template = nil
|
179
|
+
self.universe_domain = universe_domain
|
140
180
|
self.root_url = root_url
|
141
181
|
self.base_path = base_path
|
142
182
|
self.client_name = client_name || 'google-api-ruby-client'
|
@@ -279,7 +319,7 @@ module Google
|
|
279
319
|
# Name of the field in the result containing the items. Defaults to :items
|
280
320
|
# @param [Boolean] cache
|
281
321
|
# True (default) if results should be cached so multiple iterations can be used.
|
282
|
-
# @return [
|
322
|
+
# @return [Enumerable]
|
283
323
|
# @yield [token, service]
|
284
324
|
# Current page token & service instance
|
285
325
|
# @yieldparam [String] token
|
@@ -296,6 +336,50 @@ module Google
|
|
296
336
|
return PagedResults.new(self, max: max, items: items, cache: cache, response_page_token: response_page_token, &block)
|
297
337
|
end
|
298
338
|
|
339
|
+
# Verify that the universe domain setting matches the universe domain
|
340
|
+
# in the credentials, if present.
|
341
|
+
#
|
342
|
+
# @raise [Google::Apis::UniverseDomainError] if there is a mismatch
|
343
|
+
def verify_universe_domain!
|
344
|
+
auth = authorization
|
345
|
+
auth_universe_domain = auth.universe_domain if auth.respond_to? :universe_domain
|
346
|
+
if auth_universe_domain && auth_universe_domain != universe_domain
|
347
|
+
raise UniverseDomainError,
|
348
|
+
"Universe domain is #{universe_domain} but credentials are in #{auth_universe_domain}"
|
349
|
+
end
|
350
|
+
true
|
351
|
+
end
|
352
|
+
|
353
|
+
# Restarts An interrupted Resumable upload
|
354
|
+
# @param [String] bucket
|
355
|
+
# Name of the bucket where the upload is being performed.
|
356
|
+
# @param [IO, String] upload_source
|
357
|
+
# IO stream or filename containing content to upload
|
358
|
+
# @param [IO, String] upload_id
|
359
|
+
# unique id generated for an ongoing upload
|
360
|
+
|
361
|
+
def restart_resumable_upload(bucket, upload_source, upload_id, options: nil)
|
362
|
+
command = make_storage_upload_command(:put, 'b/{bucket}/o', options)
|
363
|
+
command.upload_source = upload_source
|
364
|
+
command.upload_id = upload_id
|
365
|
+
command.params['bucket'] = bucket unless bucket.nil?
|
366
|
+
execute_or_queue_command(command)
|
367
|
+
end
|
368
|
+
|
369
|
+
# Deletes An interrupted Resumable upload
|
370
|
+
# @param [String] bucket
|
371
|
+
# Name of the bucket where the upload is being performed.
|
372
|
+
# @param [IO, String] upload_id
|
373
|
+
# unique id generated for an ongoing upload
|
374
|
+
|
375
|
+
def delete_resumable_upload(bucket, upload_id, options: nil)
|
376
|
+
command = make_storage_upload_command(:delete, 'b/{bucket}/o', options)
|
377
|
+
command.upload_id = upload_id
|
378
|
+
command.params['bucket'] = bucket unless bucket.nil?
|
379
|
+
command.delete_upload = options[:delete_upload] unless options[:delete_upload].nil?
|
380
|
+
execute_or_queue_command(command)
|
381
|
+
end
|
382
|
+
|
299
383
|
protected
|
300
384
|
|
301
385
|
# Create a new upload command.
|
@@ -308,6 +392,7 @@ module Google
|
|
308
392
|
# Request-specific options
|
309
393
|
# @return [Google::Apis::Core::UploadCommand]
|
310
394
|
def make_upload_command(method, path, options)
|
395
|
+
verify_universe_domain!
|
311
396
|
template = Addressable::Template.new(root_url + upload_path + path)
|
312
397
|
if batch?
|
313
398
|
command = MultipartUploadCommand.new(method, template, client_version: client_version)
|
@@ -332,6 +417,7 @@ module Google
|
|
332
417
|
# Request-specific options
|
333
418
|
# @return [Google::Apis::Core::StorageUploadCommand]
|
334
419
|
def make_storage_upload_command(method, path, options)
|
420
|
+
verify_universe_domain!
|
335
421
|
template = Addressable::Template.new(root_url + upload_path + path)
|
336
422
|
command = StorageUploadCommand.new(method, template, client_version: client_version)
|
337
423
|
command.options = request_options.merge(options)
|
@@ -349,6 +435,7 @@ module Google
|
|
349
435
|
# Request-specific options
|
350
436
|
# @return [Google::Apis::Core::DownloadCommand]
|
351
437
|
def make_download_command(method, path, options)
|
438
|
+
verify_universe_domain!
|
352
439
|
template = Addressable::Template.new(root_url + base_path + path)
|
353
440
|
command = DownloadCommand.new(method, template, client_version: client_version)
|
354
441
|
command.options = request_options.merge(options)
|
@@ -368,6 +455,7 @@ module Google
|
|
368
455
|
# Request-specific options
|
369
456
|
# @return [Google::Apis::Core::StorageDownloadCommand]
|
370
457
|
def make_storage_download_command(method, path, options)
|
458
|
+
verify_universe_domain!
|
371
459
|
template = Addressable::Template.new(root_url + base_path + path)
|
372
460
|
command = StorageDownloadCommand.new(method, template, client_version: client_version)
|
373
461
|
command.options = request_options.merge(options)
|
@@ -386,6 +474,7 @@ module Google
|
|
386
474
|
# Request-specific options
|
387
475
|
# @return [Google::Apis::Core::DownloadCommand]
|
388
476
|
def make_simple_command(method, path, options)
|
477
|
+
verify_universe_domain!
|
389
478
|
full_path =
|
390
479
|
if path.start_with? "/"
|
391
480
|
path[1..-1]
|
@@ -15,6 +15,7 @@
|
|
15
15
|
require 'google/apis/core/api_command'
|
16
16
|
require 'google/apis/errors'
|
17
17
|
require 'addressable/uri'
|
18
|
+
require 'pathname'
|
18
19
|
|
19
20
|
module Google
|
20
21
|
module Apis
|
@@ -35,14 +36,17 @@ module Google
|
|
35
36
|
@state = :start
|
36
37
|
@download_url = nil
|
37
38
|
@offset = 0
|
38
|
-
if download_dest.
|
39
|
+
if @download_dest.is_a?(Pathname)
|
40
|
+
@download_io = File.open(download_dest, 'wb')
|
41
|
+
@close_io_on_finish = true
|
42
|
+
elsif download_dest.respond_to?(:write)
|
39
43
|
@download_io = download_dest
|
40
44
|
@close_io_on_finish = false
|
41
45
|
elsif download_dest.is_a?(String)
|
42
46
|
@download_io = File.open(download_dest, 'wb')
|
43
47
|
@close_io_on_finish = true
|
44
48
|
else
|
45
|
-
@download_io = StringIO.new('', 'wb')
|
49
|
+
@download_io = StringIO.new(+'', 'wb')
|
46
50
|
@close_io_on_finish = false
|
47
51
|
end
|
48
52
|
super
|
@@ -283,7 +283,7 @@ module Google
|
|
283
283
|
# @yield [nil, err] if block given
|
284
284
|
# @raise [StandardError] if no block
|
285
285
|
def error(err, rethrow: false, &block)
|
286
|
-
logger.debug { sprintf('Error - %s', PP.pp(err, '')) }
|
286
|
+
logger.debug { sprintf('Error - %s', PP.pp(err, +'')) }
|
287
287
|
if err.is_a?(HTTPClient::BadResponseError)
|
288
288
|
begin
|
289
289
|
res = err.res
|
@@ -292,7 +292,12 @@ module Google
|
|
292
292
|
rescue Google::Apis::Error => e
|
293
293
|
err = e
|
294
294
|
end
|
295
|
-
elsif err.is_a?(HTTPClient::TimeoutError) ||
|
295
|
+
elsif err.is_a?(HTTPClient::TimeoutError) ||
|
296
|
+
err.is_a?(SocketError) ||
|
297
|
+
err.is_a?(HTTPClient::KeepAliveDisconnected) ||
|
298
|
+
err.is_a?(Errno::ECONNREFUSED) ||
|
299
|
+
err.is_a?(Errno::ETIMEDOUT) ||
|
300
|
+
err.is_a?(Errno::ECONNRESET)
|
296
301
|
err = Google::Apis::TransmissionError.new(err)
|
297
302
|
end
|
298
303
|
block.call(nil, err) if block_given?
|
@@ -348,6 +353,12 @@ module Google
|
|
348
353
|
[:post, :put].include?(method) && body.nil?
|
349
354
|
end
|
350
355
|
|
356
|
+
# Set the API version header for the service if not empty.
|
357
|
+
# @return [void]
|
358
|
+
def set_api_version_header api_version
|
359
|
+
self.header['X-Goog-Api-Version'] = api_version unless api_version.empty?
|
360
|
+
end
|
361
|
+
|
351
362
|
private
|
352
363
|
|
353
364
|
UNSAFE_CLASS_NAMES = [
|
@@ -374,7 +385,7 @@ module Google
|
|
374
385
|
end
|
375
386
|
|
376
387
|
def safe_pretty_representation obj
|
377
|
-
out = ""
|
388
|
+
out = +""
|
378
389
|
printer = RedactingPP.new out, 79
|
379
390
|
printer.guard_inspect_key { printer.pp obj }
|
380
391
|
printer.flush
|
@@ -382,7 +393,7 @@ module Google
|
|
382
393
|
end
|
383
394
|
|
384
395
|
def safe_single_line_representation obj
|
385
|
-
out = ""
|
396
|
+
out = +""
|
386
397
|
printer = RedactingSingleLine.new out
|
387
398
|
printer.guard_inspect_key { printer.pp obj }
|
388
399
|
printer.flush
|
@@ -31,7 +31,7 @@ module Google
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def to_io(boundary)
|
34
|
-
part = ''
|
34
|
+
part = +''
|
35
35
|
part << "--#{boundary}\r\n"
|
36
36
|
part << "Content-Type: application/json\r\n"
|
37
37
|
@header.each do |(k, v)|
|
@@ -59,7 +59,7 @@ module Google
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def to_io(boundary)
|
62
|
-
head = ''
|
62
|
+
head = +''
|
63
63
|
head << "--#{boundary}\r\n"
|
64
64
|
@header.each do |(k, v)|
|
65
65
|
head << "#{k}: #{v}\r\n"
|
@@ -67,7 +67,7 @@ module Google
|
|
67
67
|
head << "Content-Length: #{@length}\r\n" unless @length.nil?
|
68
68
|
head << "Content-Transfer-Encoding: binary\r\n"
|
69
69
|
head << "\r\n"
|
70
|
-
Google::Apis::Core::CompositeIO.new(StringIO.new(head), @io, StringIO.new("\r\n"))
|
70
|
+
Google::Apis::Core::CompositeIO.new(StringIO.new(head), @io, StringIO.new(+"\r\n"))
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -126,7 +126,7 @@ module Google
|
|
126
126
|
# @return [IO]
|
127
127
|
# IO stream
|
128
128
|
def assemble
|
129
|
-
@parts << StringIO.new("--#{@boundary}--\r\n\r\n")
|
129
|
+
@parts << StringIO.new(+"--#{@boundary}--\r\n\r\n")
|
130
130
|
Google::Apis::Core::CompositeIO.new(*@parts)
|
131
131
|
end
|
132
132
|
end
|
@@ -25,7 +25,7 @@ module Google
|
|
25
25
|
|
26
26
|
# Execute the upload request once. Overrides the default implementation to handle streaming/chunking
|
27
27
|
# of file content.
|
28
|
-
# Note: This method is
|
28
|
+
# Note: This method is overridden from DownloadCommand in order to respond back with
|
29
29
|
# http header. All changes made to `execute_once` of DownloadCommand, should be made
|
30
30
|
# here too.
|
31
31
|
#
|
@@ -49,6 +49,14 @@ module Google
|
|
49
49
|
# @return [Integer]
|
50
50
|
attr_accessor :upload_chunk_size
|
51
51
|
|
52
|
+
# Unique upload_id of a resumable upload
|
53
|
+
# @return [String]
|
54
|
+
attr_accessor :upload_id
|
55
|
+
|
56
|
+
# Boolean Value to specify is a resumable upload is to be deleted or not
|
57
|
+
# @return [Boolean]
|
58
|
+
attr_accessor :delete_upload
|
59
|
+
|
52
60
|
# Ensure the content is readable and wrapped in an IO instance.
|
53
61
|
#
|
54
62
|
# @return [void]
|
@@ -61,7 +69,6 @@ module Google
|
|
61
69
|
# asserting that it already has a body. Form encoding is never used
|
62
70
|
# by upload requests.
|
63
71
|
self.body = '' unless self.body
|
64
|
-
|
65
72
|
super
|
66
73
|
if streamable?(upload_source)
|
67
74
|
self.upload_io = upload_source
|
@@ -73,6 +80,8 @@ module Google
|
|
73
80
|
self.upload_content_type = type&.content_type
|
74
81
|
end
|
75
82
|
@close_io_on_finish = true
|
83
|
+
elsif !upload_id.nil? && delete_upload
|
84
|
+
@close_io_on_finish = false
|
76
85
|
else
|
77
86
|
fail Google::Apis::ClientError, 'Invalid upload source'
|
78
87
|
end
|
@@ -80,7 +89,7 @@ module Google
|
|
80
89
|
|
81
90
|
# Close IO stream when command done. Only closes the stream if it was opened by the command.
|
82
91
|
def release!
|
83
|
-
upload_io.close if @close_io_on_finish
|
92
|
+
upload_io.close if @close_io_on_finish && !upload_io.nil?
|
84
93
|
end
|
85
94
|
|
86
95
|
# Execute the command, retrying as necessary
|
@@ -96,8 +105,16 @@ module Google
|
|
96
105
|
prepare!
|
97
106
|
opencensus_begin_span
|
98
107
|
@upload_chunk_size = options.upload_chunk_size
|
108
|
+
if upload_id.nil?
|
109
|
+
res = do_retry :initiate_resumable_upload, client
|
110
|
+
elsif delete_upload && !upload_id.nil?
|
111
|
+
construct_resumable_upload_url upload_id
|
112
|
+
res = do_retry :cancel_resumable_upload, client
|
113
|
+
else
|
114
|
+
construct_resumable_upload_url upload_id
|
115
|
+
res = do_retry :reinitiate_resumable_upload, client
|
116
|
+
end
|
99
117
|
|
100
|
-
do_retry :initiate_resumable_upload, client
|
101
118
|
while @upload_incomplete
|
102
119
|
res = do_retry :send_upload_command, client
|
103
120
|
end
|
@@ -131,6 +148,22 @@ module Google
|
|
131
148
|
error(e, rethrow: true)
|
132
149
|
end
|
133
150
|
|
151
|
+
# Reinitiating resumable upload
|
152
|
+
def reinitiate_resumable_upload(client)
|
153
|
+
logger.debug { sprintf('Restarting resumable upload command to %s', url) }
|
154
|
+
check_resumable_upload client
|
155
|
+
upload_io.pos = @offset
|
156
|
+
end
|
157
|
+
|
158
|
+
# Making resumable upload url from upload_id
|
159
|
+
def construct_resumable_upload_url(upload_id)
|
160
|
+
query_params = query.dup
|
161
|
+
query_params['uploadType'] = RESUMABLE
|
162
|
+
query_params['upload_id'] = upload_id
|
163
|
+
resumable_upload_params = query_params.map { |key, value| "#{key}=#{value}" }.join('&')
|
164
|
+
@upload_url = "#{url}&#{resumable_upload_params}"
|
165
|
+
end
|
166
|
+
|
134
167
|
# Send the actual content
|
135
168
|
#
|
136
169
|
# @param [HTTPClient] client
|
@@ -160,6 +193,9 @@ module Google
|
|
160
193
|
@offset += current_chunk_size if @upload_incomplete
|
161
194
|
success(result)
|
162
195
|
rescue => e
|
196
|
+
logger.warn {
|
197
|
+
"error occured please use uploadId-#{response.headers['X-GUploader-UploadID']} to resume your upload"
|
198
|
+
} unless response.nil?
|
163
199
|
upload_io.pos = @offset
|
164
200
|
error(e, rethrow: true)
|
165
201
|
end
|
@@ -182,6 +218,59 @@ module Google
|
|
182
218
|
super(status, header, body)
|
183
219
|
end
|
184
220
|
|
221
|
+
def check_resumable_upload(client)
|
222
|
+
# Setting up request header
|
223
|
+
request_header = header.dup
|
224
|
+
request_header[CONTENT_RANGE_HEADER] = "bytes */#{upload_io.size}"
|
225
|
+
request_header[CONTENT_LENGTH_HEADER] = '0'
|
226
|
+
# Initiating call
|
227
|
+
response = client.put(@upload_url, header: request_header, follow_redirect: true)
|
228
|
+
handle_resumable_upload_http_response_codes(response)
|
229
|
+
end
|
230
|
+
|
231
|
+
# Cancel resumable upload
|
232
|
+
def cancel_resumable_upload(client)
|
233
|
+
# Setting up request header
|
234
|
+
request_header = header.dup
|
235
|
+
request_header[CONTENT_LENGTH_HEADER] = '0'
|
236
|
+
# Initiating call
|
237
|
+
response = client.delete(@upload_url, header: request_header, follow_redirect: true)
|
238
|
+
handle_resumable_upload_http_response_codes(response)
|
239
|
+
|
240
|
+
if !@upload_incomplete && (400..499).include?(response.code.to_i)
|
241
|
+
@close_io_on_finish = true
|
242
|
+
true # method returns true if upload is successfully cancelled
|
243
|
+
else
|
244
|
+
logger.debug { sprintf("Failed to cancel upload session. Response: #{response.code} - #{response.body}") }
|
245
|
+
end
|
246
|
+
|
247
|
+
end
|
248
|
+
|
249
|
+
def handle_resumable_upload_http_response_codes(response)
|
250
|
+
code = response.code.to_i
|
251
|
+
|
252
|
+
case code
|
253
|
+
when 308
|
254
|
+
if response.headers['Range']
|
255
|
+
range = response.headers['Range']
|
256
|
+
@offset = range.split('-').last.to_i + 1
|
257
|
+
logger.debug { sprintf("Upload is incomplete. Bytes uploaded so far: #{range}") }
|
258
|
+
else
|
259
|
+
logger.debug { sprintf('No bytes uploaded yet.') }
|
260
|
+
end
|
261
|
+
@upload_incomplete = true
|
262
|
+
when 400..499
|
263
|
+
# Upload is canceled
|
264
|
+
@upload_incomplete = false
|
265
|
+
when 200, 201
|
266
|
+
# Upload is complete.
|
267
|
+
@upload_incomplete = false
|
268
|
+
else
|
269
|
+
logger.debug { sprintf("Unexpected response: #{response.code} - #{response.body}") }
|
270
|
+
@upload_incomplete = true
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
185
274
|
def streamable?(upload_source)
|
186
275
|
upload_source.is_a?(IO) || upload_source.is_a?(StringIO) || upload_source.is_a?(Tempfile)
|
187
276
|
end
|
data/lib/google/apis/errors.rb
CHANGED
@@ -43,7 +43,7 @@ module Google
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def inspect
|
46
|
-
extra = ""
|
46
|
+
extra = +""
|
47
47
|
extra << " status_code: #{status_code.inspect}" unless status_code.nil?
|
48
48
|
extra << " header: #{header.inspect}" unless header.nil?
|
49
49
|
extra << " body: #{body.inspect}" unless body.nil?
|
@@ -89,5 +89,9 @@ module Google
|
|
89
89
|
# Error class for problems in batch requests.
|
90
90
|
class BatchError < Error
|
91
91
|
end
|
92
|
+
|
93
|
+
# Error class for universe domain issues
|
94
|
+
class UniverseDomainError < Error
|
95
|
+
end
|
92
96
|
end
|
93
97
|
end
|
data/lib/google/apis/options.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-apis-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Google LLC
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: representable
|
@@ -82,29 +81,23 @@ dependencies:
|
|
82
81
|
name: googleauth
|
83
82
|
requirement: !ruby/object:Gem::Requirement
|
84
83
|
requirements:
|
85
|
-
- - "
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
version: 0.16.2
|
88
|
-
- - "<"
|
84
|
+
- - "~>"
|
89
85
|
- !ruby/object:Gem::Version
|
90
|
-
version:
|
86
|
+
version: '1.9'
|
91
87
|
type: :runtime
|
92
88
|
prerelease: false
|
93
89
|
version_requirements: !ruby/object:Gem::Requirement
|
94
90
|
requirements:
|
95
|
-
- - "
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: 0.16.2
|
98
|
-
- - "<"
|
91
|
+
- - "~>"
|
99
92
|
- !ruby/object:Gem::Version
|
100
|
-
version:
|
93
|
+
version: '1.9'
|
101
94
|
- !ruby/object:Gem::Dependency
|
102
95
|
name: httpclient
|
103
96
|
requirement: !ruby/object:Gem::Requirement
|
104
97
|
requirements:
|
105
98
|
- - ">="
|
106
99
|
- !ruby/object:Gem::Version
|
107
|
-
version: 2.8.
|
100
|
+
version: 2.8.3
|
108
101
|
- - "<"
|
109
102
|
- !ruby/object:Gem::Version
|
110
103
|
version: 3.a
|
@@ -114,26 +107,12 @@ dependencies:
|
|
114
107
|
requirements:
|
115
108
|
- - ">="
|
116
109
|
- !ruby/object:Gem::Version
|
117
|
-
version: 2.8.
|
110
|
+
version: 2.8.3
|
118
111
|
- - "<"
|
119
112
|
- !ruby/object:Gem::Version
|
120
113
|
version: 3.a
|
121
114
|
- !ruby/object:Gem::Dependency
|
122
|
-
name:
|
123
|
-
requirement: !ruby/object:Gem::Requirement
|
124
|
-
requirements:
|
125
|
-
- - ">="
|
126
|
-
- !ruby/object:Gem::Version
|
127
|
-
version: '0'
|
128
|
-
type: :runtime
|
129
|
-
prerelease: false
|
130
|
-
version_requirements: !ruby/object:Gem::Requirement
|
131
|
-
requirements:
|
132
|
-
- - ">="
|
133
|
-
- !ruby/object:Gem::Version
|
134
|
-
version: '0'
|
135
|
-
- !ruby/object:Gem::Dependency
|
136
|
-
name: webrick
|
115
|
+
name: mutex_m
|
137
116
|
requirement: !ruby/object:Gem::Requirement
|
138
117
|
requirements:
|
139
118
|
- - ">="
|
@@ -146,7 +125,6 @@ dependencies:
|
|
146
125
|
- - ">="
|
147
126
|
- !ruby/object:Gem::Version
|
148
127
|
version: '0'
|
149
|
-
description:
|
150
128
|
email: googleapis-packages@google.com
|
151
129
|
executables: []
|
152
130
|
extensions: []
|
@@ -186,9 +164,8 @@ licenses:
|
|
186
164
|
metadata:
|
187
165
|
bug_tracker_uri: https://github.com/googleapis/google-api-ruby-client/issues
|
188
166
|
changelog_uri: https://github.com/googleapis/google-api-ruby-client/tree/main/google-apis-core/CHANGELOG.md
|
189
|
-
documentation_uri: https://googleapis.dev/ruby/google-apis-core/v0.
|
167
|
+
documentation_uri: https://googleapis.dev/ruby/google-apis-core/v0.18.0
|
190
168
|
source_code_uri: https://github.com/googleapis/google-api-ruby-client/tree/main/google-apis-core
|
191
|
-
post_install_message:
|
192
169
|
rdoc_options: []
|
193
170
|
require_paths:
|
194
171
|
- lib
|
@@ -196,15 +173,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
196
173
|
requirements:
|
197
174
|
- - ">="
|
198
175
|
- !ruby/object:Gem::Version
|
199
|
-
version: '
|
176
|
+
version: '3.1'
|
200
177
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
178
|
requirements:
|
202
179
|
- - ">="
|
203
180
|
- !ruby/object:Gem::Version
|
204
181
|
version: '0'
|
205
182
|
requirements: []
|
206
|
-
rubygems_version: 3.
|
207
|
-
signing_key:
|
183
|
+
rubygems_version: 3.6.9
|
208
184
|
specification_version: 4
|
209
185
|
summary: Common utility and base classes for legacy Google REST clients
|
210
186
|
test_files: []
|