google-apis-core 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7910ff49bab7cf667d1a049d41c8b7365b17e75aa14e1aff59c80eddb405f3b4
|
4
|
+
data.tar.gz: ccaafe8161b7119b394d3678dfaaafd70f13e136e63ac23096edd08ed14d9aaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b627f63c2fb4270acbc9c5cddd31a3e5bffe977d1a336b08e2129d5127250154a0fcd96b062709bec5d24896daacc3fc58ef404599995dbc5d7bcea226430a71
|
7
|
+
data.tar.gz: a8d4b1d18d1a97c2b6bb3973e138c97b82e6e0d587ba14e319f26a30891455b96d6ef519a9376ec578c93acaa0e5ed7b20b0d39ca3192aec8d3b92267bb34bec
|
data/CHANGELOG.md
CHANGED
@@ -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)
|
@@ -275,7 +275,7 @@ module Google
|
|
275
275
|
# @yield [nil, err] if block given
|
276
276
|
# @raise [StandardError] if no block
|
277
277
|
def error(err, rethrow: false, &block)
|
278
|
-
logger.
|
278
|
+
logger.error { sprintf('Error - %s', PP.pp(err, '')) }
|
279
279
|
if err.is_a?(HTTPClient::BadResponseError)
|
280
280
|
begin
|
281
281
|
res = err.res
|
@@ -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.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-06-
|
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.
|
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: []
|