google-apis-core 0.4.2 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de1aca07eb6dab1c4571ad1b001657b858a7c8f263591d23f76a482707c1d244
4
- data.tar.gz: 7715680088cf38a06fcf80747a047f0ebb0aaf63ed61817df26787db4f983fcd
3
+ metadata.gz: 7910ff49bab7cf667d1a049d41c8b7365b17e75aa14e1aff59c80eddb405f3b4
4
+ data.tar.gz: ccaafe8161b7119b394d3678dfaaafd70f13e136e63ac23096edd08ed14d9aaa
5
5
  SHA512:
6
- metadata.gz: '029c926e8f4dcc1371f68def113598ca73cb4fc6982376c53175f40240a537b2dbce3e7cf041b54ae8b501867f0e728f596c1e70ed0abd798ba695605a7ca5fb'
7
- data.tar.gz: fb2ef0252bfcdab2b3e45e07252cbed43a3a73dd4b72c32f7024a62bec18cf557905f75a5a7c56366b3466db29b353dd1a94ceee9a6a8160b05573231bcad237
6
+ metadata.gz: b627f63c2fb4270acbc9c5cddd31a3e5bffe977d1a336b08e2129d5127250154a0fcd96b062709bec5d24896daacc3fc58ef404599995dbc5d7bcea226430a71
7
+ data.tar.gz: a8d4b1d18d1a97c2b6bb3973e138c97b82e6e0d587ba14e319f26a30891455b96d6ef519a9376ec578c93acaa0e5ed7b20b0d39ca3192aec8d3b92267bb34bec
data/CHANGELOG.md CHANGED
@@ -1,32 +1,48 @@
1
1
  # Release History
2
2
 
3
- ### [0.4.2](https://www.github.com/googleapis/google-api-ruby-client/compare/google-apis-core/v0.4.1...google-apis-core/v0.4.2) (2022-01-21)
3
+ ### 0.7.0 (2022-06-30)
4
4
 
5
+ #### Features
5
6
 
6
- ### Bug Fixes
7
+ * Add storage specific download to respond with http header
7
8
 
8
- * **core:** Support for max elapsed time configuration. ([241361e](https://www.github.com/googleapis/google-api-ruby-client/commit/241361e1a47d1aeac09ecd1f24099c8fc83e4508))
9
+ ### 0.6.0 (2022-06-15)
9
10
 
10
- ## 0.4.1 (2021-07-19)
11
+ #### Features
12
+
13
+ * add few more errors as retriable errors
14
+
15
+ ### 0.5.0 (2022-05-15)
16
+
17
+ #### Features
18
+
19
+ * Add support for retry options to be configurable
20
+
21
+ ### 0.4.2 (2022-01-21)
22
+
23
+ #### Bug Fixes
24
+
25
+ * Support for max elapsed time configuration.
26
+
27
+ ### 0.4.1 (2021-07-19)
11
28
 
12
29
  * FIX: Prevent duplicated pagination when a response returns an empty string as the next page token.
13
30
 
14
- ## 0.4.0 (2021-06-28)
31
+ ### 0.4.0 (2021-06-28)
15
32
 
16
33
  * Expanded googleauth dependency to include future 1.x versions
17
34
 
18
- ## [0.3.0](https://www.github.com/googleapis/google-api-ruby-client/compare/google-apis-core/v0.2.1...v0.3.0) (2021-03-07)
19
-
20
- ### Features
35
+ ### 0.3.0 (2021-03-07)
21
36
 
22
- * Drop support for Ruby 2.4 and add support for Ruby 3.0 ([d871146](https://www.github.com/googleapis/google-api-ruby-client/commit/d871146916f3dd19a12820c03068b3861a4bc879))
37
+ #### Features
23
38
 
24
- ### [0.2.1](https://www.github.com/googleapis/google-api-ruby-client/compare/google-apis-core/v0.2.0...v0.2.1) (2021-01-25)
39
+ * Drop support for Ruby 2.4 and add support for Ruby 3.0
25
40
 
41
+ ### 0.2.1 (2021-01-25)
26
42
 
27
- ### Bug Fixes
43
+ #### Bug Fixes
28
44
 
29
- * **core:** Add webrick to the gem dependencies, for Ruby 3 compatibility ([25824f2](https://www.github.com/googleapis/google-api-ruby-client/commit/25824f2512fa96d4d90e220ac038c9b3b2a6a0d1))
45
+ * Add webrick to the gem dependencies, for Ruby 3 compatibility
30
46
 
31
47
  ### 0.2.0 (2021-01-06)
32
48
 
@@ -20,6 +20,7 @@ require 'google/apis/core/api_command'
20
20
  require 'google/apis/core/batch'
21
21
  require 'google/apis/core/upload'
22
22
  require 'google/apis/core/download'
23
+ require 'google/apis/core/storage_download'
23
24
  require 'google/apis/options'
24
25
  require 'googleauth'
25
26
  require 'httpclient'
@@ -335,6 +336,25 @@ module Google
335
336
  command
336
337
  end
337
338
 
339
+ # Create a new storage download command. This is specifically for storage because
340
+ # we want to return response header too in the response.
341
+ #
342
+ # @param [symbol] method
343
+ # HTTP method for uploading (typically :get)
344
+ # @param [String] path
345
+ # Additional path to download endpoint, appended to API base path
346
+ # @param [Hash, Google::Apis::RequestOptions] options
347
+ # Request-specific options
348
+ # @return [Google::Apis::Core::StorageDownloadCommand]
349
+ def make_storage_download_command(method, path, options)
350
+ template = Addressable::Template.new(root_url + base_path + path)
351
+ command = StorageDownloadCommand.new(method, template, client_version: client_version)
352
+ command.options = request_options.merge(options)
353
+ command.query['alt'] = 'media'
354
+ apply_command_defaults(command)
355
+ command
356
+ end
357
+
338
358
  # Create a new command.
339
359
  #
340
360
  # @param [symbol] method
@@ -120,7 +120,7 @@ module Google
120
120
  end
121
121
 
122
122
  def ensure_valid_command(command)
123
- if command.is_a?(Google::Apis::Core::BaseUploadCommand) || command.is_a?(Google::Apis::Core::DownloadCommand)
123
+ if command.is_a?(Google::Apis::Core::BaseUploadCommand) || command.is_a?(Google::Apis::Core::DownloadCommand) || command.is_a?(Google::Apis::Core::StorageDownloadCommand)
124
124
  fail Google::Apis::ClientError, 'Can not include media requests in batch'
125
125
  end
126
126
  fail Google::Apis::ClientError, 'Invalid command object' unless command.is_a?(HttpCommand)
@@ -27,7 +27,10 @@ module Google
27
27
  class HttpCommand
28
28
  include Logging
29
29
 
30
- RETRIABLE_ERRORS = [Google::Apis::ServerError, Google::Apis::RateLimitError, Google::Apis::TransmissionError]
30
+ RETRIABLE_ERRORS = [Google::Apis::ServerError,
31
+ Google::Apis::RateLimitError,
32
+ Google::Apis::TransmissionError,
33
+ Google::Apis::RequestTimeOutError]
31
34
 
32
35
  begin
33
36
  require 'opencensus'
@@ -101,8 +104,9 @@ module Google
101
104
  begin
102
105
  Retriable.retriable tries: options.retries + 1,
103
106
  max_elapsed_time: options.max_elapsed_time,
104
- base_interval: 1,
105
- multiplier: 2,
107
+ base_interval: options.base_interval,
108
+ max_interval: options.max_interval,
109
+ multiplier: options.multiplier,
106
110
  on: RETRIABLE_ERRORS do |try|
107
111
  # This 2nd level retriable only catches auth errors, and supports 1 retry, which allows
108
112
  # auth to be re-attempted without having to retry all sorts of other failures like
@@ -224,6 +228,9 @@ module Google
224
228
  when 429
225
229
  message ||= 'Rate limit exceeded'
226
230
  raise Google::Apis::RateLimitError.new(message, status_code: status, header: header, body: body)
231
+ when 408
232
+ message ||= 'Request time out'
233
+ raise Google::Apis::RequestTimeOutError.new(message, status_code: status, header: header, body: body)
227
234
  when 304, 400, 402...500
228
235
  message ||= 'Invalid request'
229
236
  raise Google::Apis::ClientError.new(message, status_code: status, header: header, body: body)
@@ -268,7 +275,7 @@ module Google
268
275
  # @yield [nil, err] if block given
269
276
  # @raise [StandardError] if no block
270
277
  def error(err, rethrow: false, &block)
271
- logger.debug { sprintf('Error - %s', PP.pp(err, '')) }
278
+ logger.error { sprintf('Error - %s', PP.pp(err, '')) }
272
279
  if err.is_a?(HTTPClient::BadResponseError)
273
280
  begin
274
281
  res = err.res
@@ -277,7 +284,7 @@ module Google
277
284
  rescue Google::Apis::Error => e
278
285
  err = e
279
286
  end
280
- elsif err.is_a?(HTTPClient::TimeoutError) || err.is_a?(SocketError)
287
+ elsif err.is_a?(HTTPClient::TimeoutError) || err.is_a?(SocketError) || err.is_a?(HTTPClient::KeepAliveDisconnected) || err.is_a?(Errno::ECONNREFUSED) || err.is_a?(Errno::ETIMEDOUT)
281
288
  err = Google::Apis::TransmissionError.new(err)
282
289
  end
283
290
  block.call(nil, err) if block_given?
@@ -0,0 +1,93 @@
1
+ # Copyright 2022 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'google/apis/core/api_command'
16
+ require 'google/apis/errors'
17
+ require 'addressable/uri'
18
+
19
+ module Google
20
+ module Apis
21
+ module Core
22
+ # Streaming/resumable media download support specifically for storage API so that
23
+ # we can respond with response headers too.
24
+ class StorageDownloadCommand < DownloadCommand
25
+
26
+ # Execute the upload request once. Overrides the default implementation to handle streaming/chunking
27
+ # of file content.
28
+ # Note: This method is overriden from DownloadCommand in order to respond back with
29
+ # http header. All changes made to `execute_once` of DownloadCommand, should be made
30
+ # here too.
31
+ #
32
+ # @private
33
+ # @param [HTTPClient] client
34
+ # HTTP client
35
+ # @yield [result, err] Result or error if block supplied
36
+ # @return [Object]
37
+ # @raise [Google::Apis::ServerError] An error occurred on the server and the request can be retried
38
+ # @raise [Google::Apis::ClientError] The request is invalid and should not be retried without modification
39
+ # @raise [Google::Apis::AuthorizationError] Authorization is required
40
+ def execute_once(client, &block)
41
+ request_header = header.dup
42
+ apply_request_options(request_header)
43
+ download_offset = nil
44
+
45
+ if @offset > 0
46
+ logger.debug { sprintf('Resuming download from offset %d', @offset) }
47
+ request_header[RANGE_HEADER] = sprintf('bytes=%d-', @offset)
48
+ end
49
+
50
+ http_res = client.get(url.to_s,
51
+ query: query,
52
+ header: request_header,
53
+ follow_redirect: true) do |res, chunk|
54
+ status = res.http_header.status_code.to_i
55
+ next unless OK_STATUS.include?(status)
56
+
57
+ download_offset ||= (status == 206 ? @offset : 0)
58
+ download_offset += chunk.bytesize
59
+
60
+ if download_offset - chunk.bytesize == @offset
61
+ next_chunk = chunk
62
+ else
63
+ # Oh no! Requested a chunk, but received the entire content
64
+ chunk_index = @offset - (download_offset - chunk.bytesize)
65
+ next_chunk = chunk.byteslice(chunk_index..-1)
66
+ next if next_chunk.nil?
67
+ end
68
+
69
+ # logger.debug { sprintf('Writing chunk (%d bytes, %d total)', chunk.length, bytes_read) }
70
+ @download_io.write(next_chunk)
71
+
72
+ @offset += next_chunk.bytesize
73
+ end
74
+
75
+ @download_io.flush if @download_io.respond_to?(:flush)
76
+
77
+ if @close_io_on_finish
78
+ result = nil
79
+ else
80
+ result = @download_io
81
+ end
82
+ check_status(http_res.status.to_i, http_res.header, http_res.body)
83
+ # In case of file download in storage, we need to respond back with http
84
+ # header along with the actual object.
85
+ success([result, http_res], &block)
86
+ rescue => e
87
+ @download_io.flush if @download_io.respond_to?(:flush)
88
+ error(e, rethrow: true, &block)
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -16,7 +16,7 @@ module Google
16
16
  module Apis
17
17
  module Core
18
18
  # Core version
19
- VERSION = "0.4.2".freeze
19
+ VERSION = "0.7.0".freeze
20
20
  end
21
21
  end
22
22
  end
@@ -66,7 +66,11 @@ module Google
66
66
  class ClientError < Error
67
67
  end
68
68
 
69
- # A 4xx class HTTP error occurred.
69
+ # A 408 HTTP error occurred.
70
+ class RequestTimeOutError < ClientError
71
+ end
72
+
73
+ # A 429 HTTP error occurred.
70
74
  class RateLimitError < Error
71
75
  end
72
76
 
@@ -29,6 +29,9 @@ module Google
29
29
  :authorization,
30
30
  :retries,
31
31
  :max_elapsed_time,
32
+ :base_interval,
33
+ :max_interval,
34
+ :multiplier,
32
35
  :header,
33
36
  :normalize_unicode,
34
37
  :skip_serialization,
@@ -69,6 +72,13 @@ module Google
69
72
  # @return [Fixnum] Number of times to retry requests on server error.
70
73
  # @!attribute [rw] max_elapsed_time
71
74
  # @return [Fixnum] Total time in seconds that requests are allowed to keep being retried.
75
+ # @!attribute [rw] base_interval
76
+ # @return [Float] The initial interval in seconds between tries.
77
+ # @!attribute [rw] max_interval
78
+ # @return [Fixnum] The maximum interval in seconds that any individual retry can reach.
79
+ # @!attribute [rw] multiplier
80
+ # @return [rw] Each successive interval grows by this factor. A multipler of 1.5 means the next interval
81
+ # will be 1.5x the current interval.
72
82
  # @!attribute [rw] header
73
83
  # @return [Hash<String,String>] Additional HTTP headers to include in requests.
74
84
  # @!attribute [rw] normalize_unicode
@@ -110,6 +120,9 @@ module Google
110
120
  ClientOptions.default.transparent_gzip_decompression = true
111
121
  RequestOptions.default.retries = 0
112
122
  RequestOptions.default.max_elapsed_time = 900
123
+ RequestOptions.default.base_interval = 1
124
+ RequestOptions.default.max_interval = 60
125
+ RequestOptions.default.multiplier = 2
113
126
  RequestOptions.default.normalize_unicode = false
114
127
  RequestOptions.default.skip_serialization = false
115
128
  RequestOptions.default.skip_deserialization = false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-apis-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Google LLC
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-21 00:00:00.000000000 Z
11
+ date: 2022-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: representable
@@ -174,6 +174,7 @@ files:
174
174
  - lib/google/apis/core/json_representation.rb
175
175
  - lib/google/apis/core/logging.rb
176
176
  - lib/google/apis/core/multipart.rb
177
+ - lib/google/apis/core/storage_download.rb
177
178
  - lib/google/apis/core/upload.rb
178
179
  - lib/google/apis/core/version.rb
179
180
  - lib/google/apis/errors.rb
@@ -184,7 +185,7 @@ licenses:
184
185
  metadata:
185
186
  bug_tracker_uri: https://github.com/googleapis/google-api-ruby-client/issues
186
187
  changelog_uri: https://github.com/googleapis/google-api-ruby-client/tree/main/google-apis-core/CHANGELOG.md
187
- documentation_uri: https://googleapis.dev/ruby/google-apis-core/v0.4.2
188
+ documentation_uri: https://googleapis.dev/ruby/google-apis-core/v0.7.0
188
189
  source_code_uri: https://github.com/googleapis/google-api-ruby-client/tree/main/google-apis-core
189
190
  post_install_message:
190
191
  rdoc_options: []
@@ -201,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
202
  - !ruby/object:Gem::Version
202
203
  version: '0'
203
204
  requirements: []
204
- rubygems_version: 3.3.5
205
+ rubygems_version: 3.3.14
205
206
  signing_key:
206
207
  specification_version: 4
207
208
  summary: Common utility and base classes for legacy Google REST clients