google-api-client 0.13.1 → 0.13.2
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 +4 -0
- data/bin/generate-api +15 -10
- data/lib/google/apis/core/download.rb +18 -12
- data/lib/google/apis/generator.rb +3 -2
- data/lib/google/apis/generator/annotator.rb +59 -23
- data/lib/google/apis/generator/model.rb +37 -1
- data/lib/google/apis/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b144a44272f08c1d1afebee4a0605f0bdfbb979
|
4
|
+
data.tar.gz: 12569977c6f24d207d619d2c07f280d8c6e88fca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 555fb114b9964c23803499d70cd90a373d49ed9a68c8821cded8b701c1bc581c26961a313b9b1583519c284a713bf57f1eda59b4167e71f1fde9ca6850439201
|
7
|
+
data.tar.gz: 733c081171862ddfac514512d4b09ed407c8b7b8099167e4a7a1c114f5d941840f5bdd085d5d890a793e0e4687d5c4094bde4b2b2cfedcd168eb2c5b3db4cba9
|
data/CHANGELOG.md
CHANGED
data/bin/generate-api
CHANGED
@@ -26,9 +26,8 @@ module Google
|
|
26
26
|
Discovery = Google::Apis::DiscoveryV1
|
27
27
|
|
28
28
|
desc 'gen OUTDIR', 'Generate ruby API from an API description'
|
29
|
-
method_options url: :array, file: :array, from_discovery: :boolean,
|
30
|
-
|
31
|
-
names_out: :string
|
29
|
+
method_options url: :array, file: :array, from_discovery: :boolean, preferred_only: :boolean,
|
30
|
+
verbose: :boolean, names: :string, names_out: :string
|
32
31
|
method_option :preferred_only, default: true
|
33
32
|
def gen(dir)
|
34
33
|
ensure_active_support
|
@@ -38,7 +37,7 @@ module Google
|
|
38
37
|
Google::Apis.logger.level = Logger::DEBUG if options[:verbose]
|
39
38
|
generate_from_url(options[:url]) if options[:url]
|
40
39
|
generate_from_file(options[:file]) if options[:file]
|
41
|
-
generate_from_discovery(preferred_only: options[:preferred_only]
|
40
|
+
generate_from_discovery(preferred_only: options[:preferred_only]) if options[:from_discovery]
|
42
41
|
create_file(options[:names_out]) { |*| generator.dump_api_names } if options[:names_out]
|
43
42
|
end
|
44
43
|
|
@@ -69,16 +68,22 @@ module Google
|
|
69
68
|
end
|
70
69
|
end
|
71
70
|
|
72
|
-
def generate_from_discovery(preferred_only: false
|
71
|
+
def generate_from_discovery(preferred_only: false)
|
73
72
|
say 'Fetching API list'
|
74
|
-
id = Array(id)
|
75
73
|
apis = discovery.list_apis
|
76
74
|
apis.items.each do |api|
|
77
|
-
if (
|
78
|
-
say sprintf('Loading %s, version %s from %s', api.name, api.version, api.discovery_rest_url)
|
79
|
-
generate_from_url(api.discovery_rest_url)
|
80
|
-
else
|
75
|
+
if (preferred_only && !api.preferred?)
|
81
76
|
say sprintf('Ignoring disoverable API %s', api.id)
|
77
|
+
else
|
78
|
+
# The Discovery service may returned cached versions of a Discovery document that are
|
79
|
+
# not the most recent revision. That means that subsequent requests to the same
|
80
|
+
# Discovery document URL can return different documents. The
|
81
|
+
# `discovery-artifact-manager` repo always holds the most recent revision, so it's
|
82
|
+
# easier to use that document than to force revision checking against the URL returned
|
83
|
+
# by the Discovery index.
|
84
|
+
discovery_rest_url = "https://raw.githubusercontent.com/googleapis/discovery-artifact-manager/master/discoveries/#{api.name}.#{api.version}.json"
|
85
|
+
say sprintf('Loading %s, version %s from %s', api.name, api.version, discovery_rest_url)
|
86
|
+
generate_from_url(discovery_rest_url)
|
82
87
|
end
|
83
88
|
end
|
84
89
|
end
|
@@ -67,12 +67,11 @@ module Google
|
|
67
67
|
def execute_once(client, &block)
|
68
68
|
request_header = header.dup
|
69
69
|
apply_request_options(request_header)
|
70
|
+
download_offset = nil
|
70
71
|
|
71
|
-
check_if_rewind_needed = false
|
72
72
|
if @offset > 0
|
73
73
|
logger.debug { sprintf('Resuming download from offset %d', @offset) }
|
74
74
|
request_header[RANGE_HEADER] = sprintf('bytes=%d-', @offset)
|
75
|
-
check_if_rewind_needed = true
|
76
75
|
end
|
77
76
|
|
78
77
|
http_res = client.get(url.to_s,
|
@@ -80,17 +79,24 @@ module Google
|
|
80
79
|
header: request_header,
|
81
80
|
follow_redirect: true) do |res, chunk|
|
82
81
|
status = res.http_header.status_code.to_i
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
@offset
|
82
|
+
next unless OK_STATUS.include?(status)
|
83
|
+
|
84
|
+
download_offset ||= (status == 206 ? @offset : 0)
|
85
|
+
download_offset += chunk.bytesize
|
86
|
+
|
87
|
+
if download_offset - chunk.bytesize == @offset
|
88
|
+
next_chunk = chunk
|
89
|
+
else
|
90
|
+
# Oh no! Requested a chunk, but received the entire content
|
91
|
+
chunk_index = @offset - (download_offset - chunk.bytesize)
|
92
|
+
next_chunk = chunk.byteslice(chunk_index..-1)
|
93
|
+
next if next_chunk.nil?
|
93
94
|
end
|
95
|
+
|
96
|
+
# logger.debug { sprintf('Writing chunk (%d bytes, %d total)', chunk.length, bytes_read) }
|
97
|
+
@download_io.write(next_chunk)
|
98
|
+
|
99
|
+
@offset += next_chunk.bytesize
|
94
100
|
end
|
95
101
|
|
96
102
|
@download_io.flush
|
@@ -27,8 +27,9 @@ module Google
|
|
27
27
|
Discovery = Google::Apis::DiscoveryV1
|
28
28
|
|
29
29
|
# Load templates
|
30
|
-
def initialize(api_names: nil)
|
31
|
-
@names = Google::Apis::Generator::Names.new(
|
30
|
+
def initialize(api_names: nil, api_names_out: nil)
|
31
|
+
@names = Google::Apis::Generator::Names.new(api_names_out || File.join(Google::Apis::ROOT, 'api_names_out.yaml'),
|
32
|
+
api_names || File.join(Google::Apis::ROOT, 'api_names.yaml'))
|
32
33
|
@module_template = Template.load('module.rb')
|
33
34
|
@service_template = Template.load('service.rb')
|
34
35
|
@classes_template = Template.load('classes.rb')
|
@@ -41,13 +41,17 @@ module Google
|
|
41
41
|
include Google::Apis::Core::Logging
|
42
42
|
include NameHelpers
|
43
43
|
|
44
|
-
def initialize(
|
45
|
-
if
|
46
|
-
logger.info { sprintf('Loading API names from %s',
|
47
|
-
@names = YAML.load(File.read(
|
44
|
+
def initialize(names_out_file_path = nil, names_file_path = nil)
|
45
|
+
if names_out_file_path
|
46
|
+
logger.info { sprintf('Loading API names from %s', names_out_file_path) }
|
47
|
+
@names = YAML.load(File.read(names_out_file_path)) || {}
|
48
48
|
else
|
49
49
|
@names = {}
|
50
50
|
end
|
51
|
+
if names_file_path
|
52
|
+
logger.info { sprintf('Loading API names from %s', names_file_path) }
|
53
|
+
@names = @names.merge(YAML.load(File.read(names_file_path)) || {})
|
54
|
+
end
|
51
55
|
@path = []
|
52
56
|
end
|
53
57
|
|
@@ -64,13 +68,6 @@ module Google
|
|
64
68
|
pick_name(normalize_param_name(@path.last))
|
65
69
|
end
|
66
70
|
|
67
|
-
# Determine the ruby method name to generate for a given method in discovery.
|
68
|
-
# @param [Google::Apis::DiscoveryV1::RestMethod] method
|
69
|
-
# Fragment of the discovery doc describing the method
|
70
|
-
def infer_method_name(method)
|
71
|
-
pick_name(infer_method_name_for_rpc(method) || infer_method_name_from_id(method))
|
72
|
-
end
|
73
|
-
|
74
71
|
def infer_property_name
|
75
72
|
pick_name(normalize_property_name(@path.last))
|
76
73
|
end
|
@@ -85,12 +82,16 @@ module Google
|
|
85
82
|
preferred_name
|
86
83
|
end
|
87
84
|
|
85
|
+
def [](key)
|
86
|
+
@names[key]
|
87
|
+
end
|
88
|
+
|
88
89
|
def []=(key, value)
|
89
90
|
@names[key] = value
|
90
91
|
end
|
91
92
|
|
92
93
|
def dump
|
93
|
-
YAML.dump(@names)
|
94
|
+
YAML.dump(Hash[@names.sort])
|
94
95
|
end
|
95
96
|
|
96
97
|
def key
|
@@ -101,12 +102,11 @@ module Google
|
|
101
102
|
@names[sprintf('%s?%s', key, opt_name)]
|
102
103
|
end
|
103
104
|
|
104
|
-
private
|
105
|
-
|
106
105
|
# For RPC style methods, pick a name based off the request objects.
|
107
106
|
# @param [Google::Apis::DiscoveryV1::RestMethod] method
|
107
|
+
# @param [Boolean] pick_name
|
108
108
|
# Fragment of the discovery doc describing the method
|
109
|
-
def infer_method_name_for_rpc(method)
|
109
|
+
def infer_method_name_for_rpc(method, pick_name = true)
|
110
110
|
return nil if method.request.nil?
|
111
111
|
parts = method.id.split('.')
|
112
112
|
parts.shift
|
@@ -122,7 +122,11 @@ module Google
|
|
122
122
|
name = name.split('_').insert(1, resource_name).join('_')
|
123
123
|
end
|
124
124
|
end
|
125
|
-
|
125
|
+
if pick_name
|
126
|
+
pick_name(name)
|
127
|
+
else
|
128
|
+
name
|
129
|
+
end
|
126
130
|
end
|
127
131
|
|
128
132
|
# For REST style methods, build a method name from the verb/resource(s) in the method
|
@@ -149,7 +153,7 @@ module Google
|
|
149
153
|
end.join('_') + '_' + resource_name
|
150
154
|
end
|
151
155
|
method_name = verb.split('_').insert(1, resource_path.split('_')).join('_')
|
152
|
-
method_name
|
156
|
+
pick_name(method_name)
|
153
157
|
end
|
154
158
|
end
|
155
159
|
|
@@ -161,10 +165,6 @@ module Google
|
|
161
165
|
include NameHelpers
|
162
166
|
include Google::Apis::Core::Logging
|
163
167
|
|
164
|
-
# Don't expose these in the API directly.
|
165
|
-
PARAMETER_BLACKLIST = %w(alt access_token bearer_token oauth_token pp prettyPrint
|
166
|
-
$.xgafv callback upload_protocol uploadType)
|
167
|
-
|
168
168
|
# Prepare the API for the templates.
|
169
169
|
# @param [Google::Apis::DiscoveryV1::RestDescription] description
|
170
170
|
# API Description
|
@@ -184,9 +184,33 @@ module Google
|
|
184
184
|
@deferred_types = []
|
185
185
|
@strip_prefixes = []
|
186
186
|
@all_methods = {}
|
187
|
+
@dup_method_names_for_rpc = collect_dup_method_names_for_rpc
|
187
188
|
@path = []
|
188
189
|
end
|
189
190
|
|
191
|
+
def collect_method_names_for_rpc(resource, method_names_for_rpc)
|
192
|
+
resource.api_methods.each do |_k, v|
|
193
|
+
# First look for the method name in the `@names` hash. If there's
|
194
|
+
# no override set, generate it without inserting the generated name
|
195
|
+
# into the `@names` hash.
|
196
|
+
method_name_for_rpc = @names[@names.key]
|
197
|
+
if method_name_for_rpc.nil?
|
198
|
+
method_name_for_rpc = @names.infer_method_name_for_rpc(v, false)
|
199
|
+
end
|
200
|
+
method_names_for_rpc << method_name_for_rpc if method_name_for_rpc
|
201
|
+
end unless resource.api_methods.nil?
|
202
|
+
|
203
|
+
resource.resources.each do |_k, v|
|
204
|
+
collect_method_names_for_rpc(v, method_names_for_rpc)
|
205
|
+
end unless resource.resources.nil?
|
206
|
+
end
|
207
|
+
|
208
|
+
def collect_dup_method_names_for_rpc
|
209
|
+
method_names_for_rpc = []
|
210
|
+
collect_method_names_for_rpc(@rest_description, method_names_for_rpc)
|
211
|
+
method_names_for_rpc.group_by{ |e| e }.select { |k, v| v.size > 1 }.map(&:first)
|
212
|
+
end
|
213
|
+
|
190
214
|
def annotate_api
|
191
215
|
@names.with_path(@rest_description.id) do
|
192
216
|
@strip_prefixes << @rest_description.name
|
@@ -196,7 +220,6 @@ module Google
|
|
196
220
|
end
|
197
221
|
end
|
198
222
|
@rest_description.force_alt_json = @names.option('force_alt_json')
|
199
|
-
@rest_description.parameters.reject! { |k, _v| PARAMETER_BLACKLIST.include?(k) }
|
200
223
|
annotate_parameters(@rest_description.parameters)
|
201
224
|
annotate_resource(@rest_description.name, @rest_description)
|
202
225
|
@rest_description.schemas.each do |k, v|
|
@@ -245,7 +268,20 @@ module Google
|
|
245
268
|
def annotate_method(method, parent_resource = nil)
|
246
269
|
@names.with_path(method.id) do
|
247
270
|
method.parent = parent_resource
|
248
|
-
|
271
|
+
# Grab the method name generated from the request object without
|
272
|
+
# inserting into, or querying, the names hash.
|
273
|
+
method_name_for_rpc = @names.infer_method_name_for_rpc(method, false)
|
274
|
+
# If `method_name_for_rpc` is a duplicate (more than one method in
|
275
|
+
# the API will generate this name), generate the method name from
|
276
|
+
# the method ID instead.
|
277
|
+
if @dup_method_names_for_rpc.include?(method_name_for_rpc)
|
278
|
+
method.generated_name = @names.infer_method_name_from_id(method)
|
279
|
+
# Otherwise, proceed as normal.
|
280
|
+
elsif method_name_for_rpc
|
281
|
+
method.generated_name = @names.infer_method_name_for_rpc(method)
|
282
|
+
else
|
283
|
+
method.generated_name = @names.infer_method_name_from_id(method)
|
284
|
+
end
|
249
285
|
check_duplicate_method(method)
|
250
286
|
annotate_parameters(method.parameters)
|
251
287
|
end
|
@@ -39,7 +39,7 @@ module Google
|
|
39
39
|
attr_accessor :path
|
40
40
|
|
41
41
|
def properties
|
42
|
-
@properties
|
42
|
+
Hash[(@properties || {}).sort]
|
43
43
|
end
|
44
44
|
|
45
45
|
def qualified_name
|
@@ -68,6 +68,10 @@ module Google
|
|
68
68
|
attr_accessor :generated_name
|
69
69
|
attr_accessor :parent
|
70
70
|
|
71
|
+
def parameters
|
72
|
+
Hash[(@parameters || {}).sort]
|
73
|
+
end
|
74
|
+
|
71
75
|
def path_parameters
|
72
76
|
return [] if parameter_order.nil? || parameters.nil?
|
73
77
|
parameter_order.map { |name| parameters[name] }.select { |param| param.location == 'path' }
|
@@ -92,6 +96,14 @@ module Google
|
|
92
96
|
class RestResource
|
93
97
|
attr_accessor :parent
|
94
98
|
|
99
|
+
def api_methods
|
100
|
+
Hash[(@api_methods || {}).sort]
|
101
|
+
end
|
102
|
+
|
103
|
+
def resources
|
104
|
+
Hash[(@resources || {}).sort]
|
105
|
+
end
|
106
|
+
|
95
107
|
def all_methods
|
96
108
|
m = []
|
97
109
|
m << api_methods.values unless api_methods.nil?
|
@@ -104,6 +116,10 @@ module Google
|
|
104
116
|
attr_accessor :force_alt_json
|
105
117
|
alias_method :force_alt_json?, :force_alt_json
|
106
118
|
|
119
|
+
# Don't expose these in the API directly.
|
120
|
+
PARAMETER_BLACKLIST = %w(alt access_token bearer_token oauth_token pp prettyPrint
|
121
|
+
$.xgafv callback upload_protocol uploadType)
|
122
|
+
|
107
123
|
def version
|
108
124
|
ActiveSupport::Inflector.camelize(@version.gsub(/\W/, '-')).gsub(/-/, '_')
|
109
125
|
end
|
@@ -125,6 +141,14 @@ module Google
|
|
125
141
|
ActiveSupport::Inflector.camelize(sprintf('%sService', class_name))
|
126
142
|
end
|
127
143
|
|
144
|
+
def api_methods
|
145
|
+
Hash[(@api_methods || {}).sort]
|
146
|
+
end
|
147
|
+
|
148
|
+
def resources
|
149
|
+
Hash[(@resources || {}).sort]
|
150
|
+
end
|
151
|
+
|
128
152
|
def all_methods
|
129
153
|
m = []
|
130
154
|
m << api_methods.values unless api_methods.nil?
|
@@ -132,11 +156,23 @@ module Google
|
|
132
156
|
m.flatten
|
133
157
|
end
|
134
158
|
|
159
|
+
def parameters
|
160
|
+
Hash[(@parameters || {}).sort].reject! { |k, _v| PARAMETER_BLACKLIST.include?(k) }
|
161
|
+
end
|
162
|
+
|
163
|
+
def schemas
|
164
|
+
Hash[(@schemas || {}).sort]
|
165
|
+
end
|
166
|
+
|
135
167
|
class Auth
|
136
168
|
class Oauth2
|
137
169
|
class Scope
|
138
170
|
attr_accessor :constant
|
139
171
|
end
|
172
|
+
|
173
|
+
def scopes
|
174
|
+
Hash[(@scopes || {}).sort]
|
175
|
+
end
|
140
176
|
end
|
141
177
|
end
|
142
178
|
end
|
data/lib/google/apis/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-api-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Bazyl
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2017-
|
14
|
+
date: 2017-08-25 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: representable
|