google-apis-core 0.6.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/lib/google/apis/core/base_service.rb +20 -0
- data/lib/google/apis/core/batch.rb +1 -1
- data/lib/google/apis/core/storage_download.rb +93 -0
- data/lib/google/apis/core/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f02ec5d554c69a4510fa74b0b1b4ddf67f7a34fb0d968374952905e44a4a663
|
4
|
+
data.tar.gz: 2d08a648b8ebdd6679bd602ccef761ee3e1b2418cd008514880912a532d0be33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f8bd3f598d3631677a518b3a744bc49ac25913a094678fb930a935e75aae6be445c0a5639a59b72ae33a6e5f8efd1dbafabcfaa210c554aaad325392ccdd7c1
|
7
|
+
data.tar.gz: 973119aa7df5d7eef5e4a870cd57bcb0980657faaddf408f95beb8962bec169d79811fbd75f3291f73ed12223625cd78833f789b0258ee26ddf42151e1aa2931
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 0.7.1 (2022-09-14)
|
4
|
+
|
5
|
+
#### Bug Fixes
|
6
|
+
|
7
|
+
* Revert "chore(core): log errors as error instead of debug([#6494](https://github.com/googleapis/google-api-ruby-client/issues/6494))" ([#11561](https://github.com/googleapis/google-api-ruby-client/issues/11561))
|
8
|
+
|
9
|
+
### 0.7.0 (2022-06-30)
|
10
|
+
|
11
|
+
#### Features
|
12
|
+
|
13
|
+
* Add storage specific download to respond with http header
|
14
|
+
|
3
15
|
### 0.6.0 (2022-06-15)
|
4
16
|
|
5
17
|
#### Features
|
@@ -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)
|
@@ -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
|
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
|
+
version: 0.7.1
|
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-
|
11
|
+
date: 2022-09-14 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.
|
188
|
+
documentation_uri: https://googleapis.dev/ruby/google-apis-core/v0.7.1
|
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: []
|