gcloud 0.12.2 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/gcloud.rb +27 -456
- data/lib/gcloud/bigquery.rb +2 -382
- data/lib/gcloud/datastore.rb +2 -576
- data/lib/gcloud/dns.rb +2 -321
- data/lib/gcloud/logging.rb +1 -322
- data/lib/gcloud/pubsub.rb +2 -476
- data/lib/gcloud/resource_manager.rb +2 -273
- data/lib/gcloud/storage.rb +2 -440
- data/lib/gcloud/translate.rb +1 -250
- data/lib/gcloud/version.rb +2 -2
- data/lib/gcloud/vision.rb +1 -501
- metadata +36 -332
- data/AUTHENTICATION.md +0 -75
- data/CHANGELOG.md +0 -382
- data/OVERVIEW.md +0 -259
- data/lib/gcloud/backoff.rb +0 -150
- data/lib/gcloud/bigquery/copy_job.rb +0 -97
- data/lib/gcloud/bigquery/credentials.rb +0 -29
- data/lib/gcloud/bigquery/data.rb +0 -239
- data/lib/gcloud/bigquery/dataset.rb +0 -753
- data/lib/gcloud/bigquery/dataset/access.rb +0 -507
- data/lib/gcloud/bigquery/dataset/list.rb +0 -169
- data/lib/gcloud/bigquery/extract_job.rb +0 -117
- data/lib/gcloud/bigquery/insert_response.rb +0 -81
- data/lib/gcloud/bigquery/job.rb +0 -299
- data/lib/gcloud/bigquery/job/list.rb +0 -172
- data/lib/gcloud/bigquery/load_job.rb +0 -202
- data/lib/gcloud/bigquery/project.rb +0 -475
- data/lib/gcloud/bigquery/query_data.rb +0 -234
- data/lib/gcloud/bigquery/query_job.rb +0 -137
- data/lib/gcloud/bigquery/schema.rb +0 -359
- data/lib/gcloud/bigquery/service.rb +0 -506
- data/lib/gcloud/bigquery/table.rb +0 -1141
- data/lib/gcloud/bigquery/table/list.rb +0 -180
- data/lib/gcloud/bigquery/view.rb +0 -475
- data/lib/gcloud/credentials.rb +0 -129
- data/lib/gcloud/datastore/commit.rb +0 -148
- data/lib/gcloud/datastore/credentials.rb +0 -35
- data/lib/gcloud/datastore/cursor.rb +0 -76
- data/lib/gcloud/datastore/dataset.rb +0 -660
- data/lib/gcloud/datastore/dataset/lookup_results.rb +0 -219
- data/lib/gcloud/datastore/dataset/query_results.rb +0 -386
- data/lib/gcloud/datastore/entity.rb +0 -449
- data/lib/gcloud/datastore/errors.rb +0 -41
- data/lib/gcloud/datastore/gql_query.rb +0 -211
- data/lib/gcloud/datastore/grpc_utils.rb +0 -132
- data/lib/gcloud/datastore/key.rb +0 -281
- data/lib/gcloud/datastore/properties.rb +0 -128
- data/lib/gcloud/datastore/query.rb +0 -348
- data/lib/gcloud/datastore/service.rb +0 -167
- data/lib/gcloud/datastore/transaction.rb +0 -362
- data/lib/gcloud/dns/change.rb +0 -158
- data/lib/gcloud/dns/change/list.rb +0 -173
- data/lib/gcloud/dns/credentials.rb +0 -29
- data/lib/gcloud/dns/importer.rb +0 -183
- data/lib/gcloud/dns/project.rb +0 -247
- data/lib/gcloud/dns/record.rb +0 -170
- data/lib/gcloud/dns/record/list.rb +0 -174
- data/lib/gcloud/dns/service.rb +0 -167
- data/lib/gcloud/dns/zone.rb +0 -759
- data/lib/gcloud/dns/zone/list.rb +0 -168
- data/lib/gcloud/dns/zone/transaction.rb +0 -176
- data/lib/gcloud/errors.rb +0 -206
- data/lib/gcloud/gce.rb +0 -56
- data/lib/gcloud/grpc_utils.rb +0 -87
- data/lib/gcloud/logging/credentials.rb +0 -29
- data/lib/gcloud/logging/entry.rb +0 -465
- data/lib/gcloud/logging/entry/http_request.rb +0 -141
- data/lib/gcloud/logging/entry/list.rb +0 -177
- data/lib/gcloud/logging/entry/operation.rb +0 -90
- data/lib/gcloud/logging/logger.rb +0 -307
- data/lib/gcloud/logging/metric.rb +0 -169
- data/lib/gcloud/logging/metric/list.rb +0 -172
- data/lib/gcloud/logging/project.rb +0 -642
- data/lib/gcloud/logging/resource.rb +0 -84
- data/lib/gcloud/logging/resource_descriptor.rb +0 -137
- data/lib/gcloud/logging/resource_descriptor/list.rb +0 -174
- data/lib/gcloud/logging/service.rb +0 -267
- data/lib/gcloud/logging/sink.rb +0 -227
- data/lib/gcloud/logging/sink/list.rb +0 -171
- data/lib/gcloud/pubsub/credentials.rb +0 -29
- data/lib/gcloud/pubsub/message.rb +0 -94
- data/lib/gcloud/pubsub/policy.rb +0 -204
- data/lib/gcloud/pubsub/project.rb +0 -482
- data/lib/gcloud/pubsub/received_message.rb +0 -160
- data/lib/gcloud/pubsub/service.rb +0 -334
- data/lib/gcloud/pubsub/subscription.rb +0 -565
- data/lib/gcloud/pubsub/subscription/list.rb +0 -208
- data/lib/gcloud/pubsub/topic.rb +0 -511
- data/lib/gcloud/pubsub/topic/list.rb +0 -174
- data/lib/gcloud/pubsub/topic/publisher.rb +0 -85
- data/lib/gcloud/resource_manager/credentials.rb +0 -30
- data/lib/gcloud/resource_manager/manager.rb +0 -266
- data/lib/gcloud/resource_manager/policy.rb +0 -211
- data/lib/gcloud/resource_manager/project.rb +0 -484
- data/lib/gcloud/resource_manager/project/list.rb +0 -167
- data/lib/gcloud/resource_manager/project/updater.rb +0 -130
- data/lib/gcloud/resource_manager/service.rb +0 -127
- data/lib/gcloud/storage/bucket.rb +0 -775
- data/lib/gcloud/storage/bucket/acl.rb +0 -810
- data/lib/gcloud/storage/bucket/cors.rb +0 -153
- data/lib/gcloud/storage/bucket/list.rb +0 -172
- data/lib/gcloud/storage/credentials.rb +0 -29
- data/lib/gcloud/storage/errors.rb +0 -65
- data/lib/gcloud/storage/file.rb +0 -842
- data/lib/gcloud/storage/file/acl.rb +0 -425
- data/lib/gcloud/storage/file/list.rb +0 -191
- data/lib/gcloud/storage/file/verifier.rb +0 -67
- data/lib/gcloud/storage/project.rb +0 -316
- data/lib/gcloud/storage/service.rb +0 -347
- data/lib/gcloud/translate/api.rb +0 -241
- data/lib/gcloud/translate/detection.rb +0 -137
- data/lib/gcloud/translate/language.rb +0 -69
- data/lib/gcloud/translate/service.rb +0 -80
- data/lib/gcloud/translate/translation.rb +0 -112
- data/lib/gcloud/vision/annotate.rb +0 -224
- data/lib/gcloud/vision/annotation.rb +0 -455
- data/lib/gcloud/vision/annotation/entity.rb +0 -234
- data/lib/gcloud/vision/annotation/face.rb +0 -1750
- data/lib/gcloud/vision/annotation/properties.rb +0 -245
- data/lib/gcloud/vision/annotation/safe_search.rb +0 -161
- data/lib/gcloud/vision/annotation/text.rb +0 -236
- data/lib/gcloud/vision/annotation/vertex.rb +0 -108
- data/lib/gcloud/vision/credentials.rb +0 -29
- data/lib/gcloud/vision/image.rb +0 -590
- data/lib/gcloud/vision/location.rb +0 -115
- data/lib/gcloud/vision/project.rb +0 -278
- data/lib/gcloud/vision/service.rb +0 -66
- data/lib/google/api/annotations.rb +0 -14
- data/lib/google/api/http.rb +0 -30
- data/lib/google/api/label.rb +0 -24
- data/lib/google/api/monitored_resource.rb +0 -25
- data/lib/google/datastore/v1beta3/datastore.rb +0 -115
- data/lib/google/datastore/v1beta3/datastore_services.rb +0 -33
- data/lib/google/datastore/v1beta3/entity.rb +0 -63
- data/lib/google/datastore/v1beta3/query.rb +0 -128
- data/lib/google/devtools/cloudtrace/v1/trace.rb +0 -78
- data/lib/google/devtools/cloudtrace/v1/trace_services.rb +0 -32
- data/lib/google/example/library/v1/library.rb +0 -91
- data/lib/google/example/library/v1/library_services.rb +0 -40
- data/lib/google/iam/v1/iam_policy.rb +0 -33
- data/lib/google/iam/v1/iam_policy_services.rb +0 -30
- data/lib/google/iam/v1/policy.rb +0 -25
- data/lib/google/logging/type/http_request.rb +0 -28
- data/lib/google/logging/type/log_severity.rb +0 -27
- data/lib/google/logging/v2/log_entry.rb +0 -44
- data/lib/google/logging/v2/logging.rb +0 -56
- data/lib/google/logging/v2/logging_config.rb +0 -59
- data/lib/google/logging/v2/logging_config_services.rb +0 -32
- data/lib/google/logging/v2/logging_metrics.rb +0 -51
- data/lib/google/logging/v2/logging_metrics_services.rb +0 -32
- data/lib/google/logging/v2/logging_services.rb +0 -31
- data/lib/google/longrunning/operations.rb +0 -50
- data/lib/google/longrunning/operations_services.rb +0 -29
- data/lib/google/protobuf/descriptor.rb +0 -0
- data/lib/google/pubsub/v1/pubsub.rb +0 -129
- data/lib/google/pubsub/v1/pubsub_services.rb +0 -56
- data/lib/google/pubsub/v1beta2/pubsub.rb +0 -126
- data/lib/google/pubsub/v1beta2/pubsub_services.rb +0 -56
- data/lib/google/rpc/code.rb +0 -32
- data/lib/google/rpc/error_details.rb +0 -61
- data/lib/google/rpc/status.rb +0 -19
- data/lib/google/type/color.rb +0 -20
- data/lib/google/type/date.rb +0 -18
- data/lib/google/type/dayofweek.rb +0 -23
- data/lib/google/type/latlng.rb +0 -17
- data/lib/google/type/money.rb +0 -18
- data/lib/google/type/timeofday.rb +0 -19
data/lib/gcloud/translate.rb
CHANGED
@@ -14,253 +14,4 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
require "gcloud"
|
17
|
-
require "
|
18
|
-
|
19
|
-
module Gcloud
|
20
|
-
##
|
21
|
-
# Creates a new object for connecting to the Translate service.
|
22
|
-
# Each call creates a new connection.
|
23
|
-
#
|
24
|
-
# Unlike other Cloud Platform services, which authenticate using a project ID
|
25
|
-
# and OAuth 2.0 credentials, Google Translate API requires a public API access
|
26
|
-
# key. (This may change in future releases of Google Translate API.) Follow
|
27
|
-
# the general instructions at [Identifying your application to
|
28
|
-
# Google](https://cloud.google.com/translate/v2/using_rest#auth), and the
|
29
|
-
# specific instructions for [Server
|
30
|
-
# keys](https://cloud.google.com/translate/v2/using_rest#creating-server-api-keys).
|
31
|
-
#
|
32
|
-
# @param [String] key a public API access key (not an OAuth 2.0 token)
|
33
|
-
# @param [Integer] retries Number of times to retry requests on server error.
|
34
|
-
# The default value is `3`. Optional.
|
35
|
-
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
36
|
-
#
|
37
|
-
# @return [Gcloud::Translate::Api]
|
38
|
-
#
|
39
|
-
# @example
|
40
|
-
# require "gcloud"
|
41
|
-
#
|
42
|
-
# translate = Gcloud.translate "api-key-abc123XYZ789"
|
43
|
-
#
|
44
|
-
# translation = translate.translate "Hello world!", to: "la"
|
45
|
-
# translation.text #=> "Salve mundi!"
|
46
|
-
#
|
47
|
-
# @example Using API Key from the environment variable.
|
48
|
-
# require "gcloud"
|
49
|
-
#
|
50
|
-
# ENV["TRANSLATE_KEY"] = "api-key-abc123XYZ789"
|
51
|
-
#
|
52
|
-
# translate = Gcloud.translate
|
53
|
-
#
|
54
|
-
# translation = translate.translate "Hello world!", to: "la"
|
55
|
-
# translation.text #=> "Salve mundi!"
|
56
|
-
#
|
57
|
-
def self.translate key = nil, retries: nil, timeout: nil
|
58
|
-
key ||= ENV["TRANSLATE_KEY"]
|
59
|
-
if key.nil?
|
60
|
-
key_missing_msg = "An API key is required to use the Translate API."
|
61
|
-
fail ArgumentError, key_missing_msg
|
62
|
-
end
|
63
|
-
|
64
|
-
Gcloud::Translate::Api.new(
|
65
|
-
Gcloud::Translate::Service.new(
|
66
|
-
key, retries: retries, timeout: timeout))
|
67
|
-
end
|
68
|
-
|
69
|
-
##
|
70
|
-
# # Google Translate API
|
71
|
-
#
|
72
|
-
# [Google Translate API](https://cloud.google.com/translate/) provides a
|
73
|
-
# simple, programmatic interface for translating an arbitrary string into any
|
74
|
-
# supported language. It is highly responsive, so websites and applications
|
75
|
-
# can integrate with Translate API for fast, dynamic translation of source
|
76
|
-
# text. Language detection is also available in cases where the source
|
77
|
-
# language is unknown.
|
78
|
-
#
|
79
|
-
# Translate API supports more than ninety different languages, from Afrikaans
|
80
|
-
# to Zulu. Used in combination, this enables translation between thousands of
|
81
|
-
# language pairs. Also, you can send in HTML and receive HTML with translated
|
82
|
-
# text back. You don't need to extract your source text or reassemble the
|
83
|
-
# translated content.
|
84
|
-
#
|
85
|
-
# ## Authenticating
|
86
|
-
#
|
87
|
-
# Unlike other Cloud Platform services, which authenticate using a project ID
|
88
|
-
# and OAuth 2.0 credentials, Translate API requires a public API access key.
|
89
|
-
# (This may change in future releases of Translate API.) Follow the general
|
90
|
-
# instructions at [Identifying your application to
|
91
|
-
# Google](https://cloud.google.com/translate/v2/using_rest#auth), and the
|
92
|
-
# specific instructions for [Server
|
93
|
-
# keys](https://cloud.google.com/translate/v2/using_rest#creating-server-api-keys).
|
94
|
-
#
|
95
|
-
# ## Translating texts
|
96
|
-
#
|
97
|
-
# Translating text from one language to another is easy (and extremely fast.)
|
98
|
-
# The only required arguments to {Gcloud::Translate::Api#translate} are a
|
99
|
-
# string and the [ISO
|
100
|
-
# 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) code of the
|
101
|
-
# language to which you wish to translate.
|
102
|
-
#
|
103
|
-
# ```ruby
|
104
|
-
# require "gcloud"
|
105
|
-
#
|
106
|
-
# gcloud = Gcloud.new
|
107
|
-
# translate = gcloud.translate
|
108
|
-
#
|
109
|
-
# translation = translate.translate "Hello world!", to: "la"
|
110
|
-
#
|
111
|
-
# puts translation #=> Salve mundi!
|
112
|
-
#
|
113
|
-
# translation.from #=> "en"
|
114
|
-
# translation.origin #=> "Hello world!"
|
115
|
-
# translation.to #=> "la"
|
116
|
-
# translation.text #=> "Salve mundi!"
|
117
|
-
# ```
|
118
|
-
#
|
119
|
-
# You may want to use the `from` option to specify the language of the source
|
120
|
-
# text, as the following example illustrates. (Single words do not give
|
121
|
-
# Translate API much to work with.)
|
122
|
-
#
|
123
|
-
# ```ruby
|
124
|
-
# require "gcloud"
|
125
|
-
#
|
126
|
-
# gcloud = Gcloud.new
|
127
|
-
# translate = gcloud.translate
|
128
|
-
#
|
129
|
-
# translation = translate.translate "chat", to: "en"
|
130
|
-
#
|
131
|
-
# translation.detected? #=> true
|
132
|
-
# translation.from #=> "en"
|
133
|
-
# translation.text #=> "chat"
|
134
|
-
#
|
135
|
-
# translation = translate.translate "chat", from: "fr", to: "en"
|
136
|
-
#
|
137
|
-
# translation.detected? #=> false
|
138
|
-
# translation.from #=> "fr"
|
139
|
-
# translation.text #=> "cat"
|
140
|
-
# ```
|
141
|
-
#
|
142
|
-
# You can pass multiple texts to {Gcloud::Translate::Api#translate}.
|
143
|
-
#
|
144
|
-
# ```ruby
|
145
|
-
# require "gcloud"
|
146
|
-
#
|
147
|
-
# gcloud = Gcloud.new
|
148
|
-
# translate = gcloud.translate
|
149
|
-
#
|
150
|
-
# translations = translate.translate "chien", "chat", from: "fr", to: "en"
|
151
|
-
#
|
152
|
-
# translations.size #=> 2
|
153
|
-
# translations[0].origin #=> "chien"
|
154
|
-
# translations[0].text #=> "dog"
|
155
|
-
# translations[1].origin #=> "chat"
|
156
|
-
# translations[1].text #=> "cat"
|
157
|
-
# ```
|
158
|
-
#
|
159
|
-
# By default, any HTML in your source text will be preserved.
|
160
|
-
#
|
161
|
-
# ```ruby
|
162
|
-
# require "gcloud"
|
163
|
-
#
|
164
|
-
# gcloud = Gcloud.new
|
165
|
-
# translate = gcloud.translate
|
166
|
-
#
|
167
|
-
# translation = translate.translate "<strong>Hello</strong> world!",
|
168
|
-
# to: :la
|
169
|
-
# translation.text #=> "<strong>Salve</strong> mundi!"
|
170
|
-
# ```
|
171
|
-
#
|
172
|
-
# ## Detecting languages
|
173
|
-
#
|
174
|
-
# You can use {Gcloud::Translate::Api#detect} to see which language the
|
175
|
-
# Translate API ranks as the most likely source language for a text. The
|
176
|
-
# `confidence` score is a float value between `0` and `1`.
|
177
|
-
#
|
178
|
-
# ```ruby
|
179
|
-
# require "gcloud"
|
180
|
-
#
|
181
|
-
# gcloud = Gcloud.new
|
182
|
-
# translate = gcloud.translate
|
183
|
-
#
|
184
|
-
# detection = translate.detect "chat"
|
185
|
-
#
|
186
|
-
# detection.text #=> "chat"
|
187
|
-
# detection.language #=> "en"
|
188
|
-
# detection.confidence #=> 0.59922177
|
189
|
-
# ```
|
190
|
-
#
|
191
|
-
# You can pass multiple texts to {Gcloud::Translate::Api#detect}.
|
192
|
-
#
|
193
|
-
# ```ruby
|
194
|
-
# require "gcloud"
|
195
|
-
#
|
196
|
-
# gcloud = Gcloud.new
|
197
|
-
# translate = gcloud.translate
|
198
|
-
#
|
199
|
-
# detections = translate.detect "chien", "chat"
|
200
|
-
#
|
201
|
-
# detections.size #=> 2
|
202
|
-
# detections[0].text #=> "chien"
|
203
|
-
# detections[0].language #=> "fr"
|
204
|
-
# detections[0].confidence #=> 0.7109375
|
205
|
-
# detections[1].text #=> "chat"
|
206
|
-
# detections[1].language #=> "en"
|
207
|
-
# detections[1].confidence #=> 0.59922177
|
208
|
-
# ```
|
209
|
-
#
|
210
|
-
# ## Listing supported languages
|
211
|
-
#
|
212
|
-
# Translate API adds new languages frequently. You can use
|
213
|
-
# {Gcloud::Translate::Api#languages} to query the list of supported languages.
|
214
|
-
#
|
215
|
-
# ```ruby
|
216
|
-
# require "gcloud"
|
217
|
-
#
|
218
|
-
# gcloud = Gcloud.new
|
219
|
-
# translate = gcloud.translate
|
220
|
-
#
|
221
|
-
# languages = translate.languages
|
222
|
-
#
|
223
|
-
# languages.size #=> 104
|
224
|
-
# languages[0].code #=> "af"
|
225
|
-
# languages[0].name #=> nil
|
226
|
-
# ```
|
227
|
-
#
|
228
|
-
# To receive the names of the supported languages, as well as their [ISO
|
229
|
-
# 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) codes, provide
|
230
|
-
# the code for the language in which you wish to receive the names.
|
231
|
-
#
|
232
|
-
# ```ruby
|
233
|
-
# require "gcloud"
|
234
|
-
#
|
235
|
-
# gcloud = Gcloud.new
|
236
|
-
# translate = gcloud.translate
|
237
|
-
#
|
238
|
-
# languages = translate.languages "en"
|
239
|
-
#
|
240
|
-
# languages.size #=> 104
|
241
|
-
# languages[0].code #=> "af"
|
242
|
-
# languages[0].name #=> "Afrikaans"
|
243
|
-
# ```
|
244
|
-
#
|
245
|
-
# ## Configuring retries and timeout
|
246
|
-
#
|
247
|
-
# You can configure how many times API requests may be automatically retried.
|
248
|
-
# When an API request fails, the response will be inspected to see if the
|
249
|
-
# request meets criteria indicating that it may succeed on retry, such as
|
250
|
-
# `500` and `503` status codes or a specific internal error code such as
|
251
|
-
# `rateLimitExceeded`. If it meets the criteria, the request will be retried
|
252
|
-
# after a delay. If another error occurs, the delay will be increased before a
|
253
|
-
# subsequent attempt, until the `retries` limit is reached.
|
254
|
-
#
|
255
|
-
# You can also set the request `timeout` value in seconds.
|
256
|
-
#
|
257
|
-
# ```ruby
|
258
|
-
# require "gcloud"
|
259
|
-
#
|
260
|
-
# gcloud = Gcloud.new
|
261
|
-
# translate = gcloud.translate retries: 10, timeout: 120
|
262
|
-
# ```
|
263
|
-
#
|
264
|
-
module Translate
|
265
|
-
end
|
266
|
-
end
|
17
|
+
require "google/cloud/translate"
|
data/lib/gcloud/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2016 Google Inc. All rights reserved.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -14,5 +14,5 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
module Gcloud
|
17
|
-
|
17
|
+
GCLOUD_VERSION = "0.20.0"
|
18
18
|
end
|
data/lib/gcloud/vision.rb
CHANGED
@@ -14,504 +14,4 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
require "gcloud"
|
17
|
-
require "
|
18
|
-
|
19
|
-
module Gcloud
|
20
|
-
##
|
21
|
-
# Creates a new object for connecting to the Vision service.
|
22
|
-
# Each call creates a new connection.
|
23
|
-
#
|
24
|
-
# @param [String] project Project identifier for the Vision service you are
|
25
|
-
# connecting to.
|
26
|
-
# @param [String, Hash] keyfile Keyfile downloaded from Google Cloud. If file
|
27
|
-
# path the file must be readable.
|
28
|
-
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
|
29
|
-
# set of resources and operations that the connection can access. See [Using
|
30
|
-
# OAuth 2.0 to Access Google
|
31
|
-
# APIs](https://developers.google.com/identity/protocols/OAuth2).
|
32
|
-
#
|
33
|
-
# The default scope is:
|
34
|
-
#
|
35
|
-
# * `https://www.googleapis.com/auth/cloud-platform`
|
36
|
-
# @param [Integer] retries Number of times to retry requests on server error.
|
37
|
-
# The default value is `3`. Optional.
|
38
|
-
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
39
|
-
#
|
40
|
-
# @return [Gcloud::Vision::Project]
|
41
|
-
#
|
42
|
-
# @example
|
43
|
-
# require "gcloud/vision"
|
44
|
-
#
|
45
|
-
# gcloud = Gcloud.new
|
46
|
-
# vision = gcloud.vision
|
47
|
-
#
|
48
|
-
# image = vision.image "path/to/landmark.jpg"
|
49
|
-
#
|
50
|
-
# landmark = image.landmark
|
51
|
-
# landmark.description #=> "Mount Rushmore"
|
52
|
-
#
|
53
|
-
def self.vision project = nil, keyfile = nil, scope: nil, retries: nil,
|
54
|
-
timeout: nil
|
55
|
-
project ||= Gcloud::Vision::Project.default_project
|
56
|
-
project = project.to_s # Always cast to a string
|
57
|
-
fail ArgumentError, "project is missing" if project.empty?
|
58
|
-
|
59
|
-
if keyfile.nil?
|
60
|
-
credentials = Gcloud::Vision::Credentials.default scope: scope
|
61
|
-
else
|
62
|
-
credentials = Gcloud::Vision::Credentials.new keyfile, scope: scope
|
63
|
-
end
|
64
|
-
|
65
|
-
Gcloud::Vision::Project.new(
|
66
|
-
Gcloud::Vision::Service.new(
|
67
|
-
project, credentials, retries: retries, timeout: timeout))
|
68
|
-
end
|
69
|
-
|
70
|
-
##
|
71
|
-
# # Google Cloud Vision
|
72
|
-
#
|
73
|
-
# Google Cloud Vision allows easy integration of vision detection features
|
74
|
-
# developer applications, including image labeling, face and landmark
|
75
|
-
# detection, optical character recognition (OCR), and tagging of explicit
|
76
|
-
# content.
|
77
|
-
#
|
78
|
-
# For more information about Cloud Vision, read the [Google Cloud Vision API
|
79
|
-
# Documentation](https://cloud.google.com/vision/docs/).
|
80
|
-
#
|
81
|
-
# The goal of gcloud-ruby is to provide an API that is comfortable to
|
82
|
-
# Rubyists. Authentication is handled by {Gcloud#vision}. You can provide the
|
83
|
-
# project and credential information to connect to the Cloud Vision service,
|
84
|
-
# or if you are running on Google Compute Engine this configuration is taken
|
85
|
-
# care of for you. You can read more about the options for connecting in the
|
86
|
-
# [Authentication
|
87
|
-
# Guide](https://googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).
|
88
|
-
#
|
89
|
-
# ## Creating images
|
90
|
-
#
|
91
|
-
# The Cloud Vision API supports a variety of image file formats, including
|
92
|
-
# JPEG, PNG8, PNG24, Animated GIF (first frame only), and RAW. See [Best
|
93
|
-
# Practices - Image Types](https://cloud.google.com/vision/docs/image-best-practices#image_types)
|
94
|
-
# for the complete list of formats. Be aware that Cloud Vision sets upper
|
95
|
-
# limits on file size as well as on the total combined size of all images in a
|
96
|
-
# request. Reducing your file size can significantly improve throughput;
|
97
|
-
# however, be careful not to reduce image quality in the process. See [Best
|
98
|
-
# Practices - Image Sizing](https://cloud.google.com/vision/docs/image-best-practices#image_sizing)
|
99
|
-
# for current file size limits.
|
100
|
-
#
|
101
|
-
# Use {Vision::Project#image} to create images for the Cloud Vision service.
|
102
|
-
# You can provide a file path:
|
103
|
-
#
|
104
|
-
# ```ruby
|
105
|
-
# require "gcloud"
|
106
|
-
#
|
107
|
-
# gcloud = Gcloud.new
|
108
|
-
# vision = gcloud.vision
|
109
|
-
#
|
110
|
-
# image = vision.image "path/to/landmark.jpg"
|
111
|
-
# ```
|
112
|
-
#
|
113
|
-
# Or, you can initialize the image with a Google Cloud Storage URI:
|
114
|
-
#
|
115
|
-
# ```ruby
|
116
|
-
# require "gcloud"
|
117
|
-
#
|
118
|
-
# gcloud = Gcloud.new
|
119
|
-
# vision = gcloud.vision
|
120
|
-
#
|
121
|
-
# image = vision.image "gs://bucket-name/path_to_image_object"
|
122
|
-
# ```
|
123
|
-
#
|
124
|
-
# Creating an Image instance does not perform an API request.
|
125
|
-
#
|
126
|
-
# ## Annotating images
|
127
|
-
#
|
128
|
-
# The instance methods on {Vision::Image} invoke Cloud Vision's detection
|
129
|
-
# features individually. Each method call makes an API request. (If you want
|
130
|
-
# to run multiple features in a single request, see the examples for
|
131
|
-
# {Vision::Project#annotate}, below.)
|
132
|
-
#
|
133
|
-
# ```ruby
|
134
|
-
# require "gcloud"
|
135
|
-
#
|
136
|
-
# gcloud = Gcloud.new
|
137
|
-
# vision = gcloud.vision
|
138
|
-
#
|
139
|
-
# image = vision.image "path/to/face.jpg"
|
140
|
-
#
|
141
|
-
# face = image.face
|
142
|
-
#
|
143
|
-
# face.features.to_h.count #=> 9
|
144
|
-
# face.features.eyes.left.pupil
|
145
|
-
# #=> #<Landmark (x: 190.41544, y: 84.4557, z: -1.3682901)>
|
146
|
-
# face.features.chin.center
|
147
|
-
# #=> #<Landmark (x: 233.21977, y: 189.47475, z: 19.487228)>
|
148
|
-
# ```
|
149
|
-
#
|
150
|
-
# To run multiple features on an image in a single request, pass the image (or
|
151
|
-
# a string file path or Storage URI) to {Vision::Project#annotate}:
|
152
|
-
#
|
153
|
-
# ```ruby
|
154
|
-
# require "gcloud"
|
155
|
-
#
|
156
|
-
# gcloud = Gcloud.new
|
157
|
-
# vision = gcloud.vision
|
158
|
-
#
|
159
|
-
# image = vision.image "path/to/face.jpg"
|
160
|
-
#
|
161
|
-
# annotation = vision.annotate image, faces: true, labels: true
|
162
|
-
# annotation.faces.count #=> 1
|
163
|
-
# annotation.labels.count #=> 4
|
164
|
-
# ```
|
165
|
-
#
|
166
|
-
# You can also perform detection tasks on multiple images in a single request:
|
167
|
-
#
|
168
|
-
# ```ruby
|
169
|
-
# require "gcloud"
|
170
|
-
#
|
171
|
-
# gcloud = Gcloud.new
|
172
|
-
# vision = gcloud.vision
|
173
|
-
#
|
174
|
-
# face_image = vision.image "path/to/face.jpg"
|
175
|
-
# landmark_image = vision.image "path/to/landmark.jpg"
|
176
|
-
#
|
177
|
-
# annotations = vision.annotate face_image,
|
178
|
-
# landmark_image,
|
179
|
-
# faces: true,
|
180
|
-
# landmarks: true,
|
181
|
-
# labels: true
|
182
|
-
#
|
183
|
-
# annotations[0].faces.count #=> 1
|
184
|
-
# annotations[0].landmarks.count #=> 0
|
185
|
-
# annotations[0].labels.count #=> 4
|
186
|
-
# annotations[1].faces.count #=> 1
|
187
|
-
# annotations[1].landmarks.count #=> 1
|
188
|
-
# annotations[1].labels.count #=> 6
|
189
|
-
# ```
|
190
|
-
#
|
191
|
-
# It is even possible to configure different features for multiple images in
|
192
|
-
# a single call using a block. The following example results in a single
|
193
|
-
# request to the Cloud Vision API:
|
194
|
-
#
|
195
|
-
# ```ruby
|
196
|
-
# require "gcloud"
|
197
|
-
#
|
198
|
-
# gcloud = Gcloud.new
|
199
|
-
# vision = gcloud.vision
|
200
|
-
#
|
201
|
-
# face_image = vision.image "path/to/face.jpg"
|
202
|
-
# landmark_image = vision.image "path/to/landmark.jpg"
|
203
|
-
# text_image = vision.image "path/to/text.png"
|
204
|
-
#
|
205
|
-
# annotations = vision.annotate do |annotate|
|
206
|
-
# annotate.annotate face_image, faces: true, labels: true
|
207
|
-
# annotate.annotate landmark_image, landmarks: true
|
208
|
-
# annotate.annotate text_image, text: true
|
209
|
-
# end
|
210
|
-
#
|
211
|
-
# annotations[0].faces.count #=> 1
|
212
|
-
# annotations[0].labels.count #=> 4
|
213
|
-
# annotations[1].landmarks.count #=> 1
|
214
|
-
# annotations[2].text.words.count #=> 28
|
215
|
-
# ```
|
216
|
-
#
|
217
|
-
# The maximum number of results returned when performing face, landmark, logo,
|
218
|
-
# and label detection are defined by {Gcloud::Vision.default_max_faces},
|
219
|
-
# {Gcloud::Vision.default_max_landmarks}, {Gcloud::Vision.default_max_logos},
|
220
|
-
# and {Gcloud::Vision.default_max_labels}, respectively. To change the global
|
221
|
-
# defaults, you can update the configuration:
|
222
|
-
#
|
223
|
-
# ```ruby
|
224
|
-
# require "gcloud"
|
225
|
-
#
|
226
|
-
# gcloud = Gcloud.new
|
227
|
-
# vision = gcloud.vision
|
228
|
-
#
|
229
|
-
# Gcloud::Vision.default_max_faces = 1
|
230
|
-
#
|
231
|
-
# annotation = vision.annotate "path/to/face.jpg", faces: true
|
232
|
-
# annotation.faces.count #=> 1
|
233
|
-
# ```
|
234
|
-
#
|
235
|
-
# Or, to override a default for a single method call, simply pass an
|
236
|
-
# integer instead of a flag:
|
237
|
-
#
|
238
|
-
# ```ruby
|
239
|
-
# require "gcloud"
|
240
|
-
#
|
241
|
-
# gcloud = Gcloud.new
|
242
|
-
# vision = gcloud.vision
|
243
|
-
#
|
244
|
-
# image = vision.image "path/to/face.jpg"
|
245
|
-
#
|
246
|
-
# # Return just one face.
|
247
|
-
# annotation = vision.annotate image, faces: 1
|
248
|
-
# # Return up to 5 faces.
|
249
|
-
# annotation = vision.annotate image, faces: 5
|
250
|
-
# ```
|
251
|
-
#
|
252
|
-
# ## Configuring retries and timeout
|
253
|
-
#
|
254
|
-
# You can configure how many times API requests may be automatically retried.
|
255
|
-
# When an API request fails, the response will be inspected to see if the
|
256
|
-
# request meets criteria indicating that it may succeed on retry, such as
|
257
|
-
# `500` and `503` status codes or a specific internal error code such as
|
258
|
-
# `rateLimitExceeded`. If it meets the criteria, the request will be retried
|
259
|
-
# after a delay. If another error occurs, the delay will be increased before a
|
260
|
-
# subsequent attempt, until the `retries` limit is reached.
|
261
|
-
#
|
262
|
-
# You can also set the request `timeout` value in seconds.
|
263
|
-
#
|
264
|
-
# ```ruby
|
265
|
-
# require "gcloud"
|
266
|
-
#
|
267
|
-
# gcloud = Gcloud.new
|
268
|
-
# vision = gcloud.vision retries: 10, timeout: 120
|
269
|
-
# ```
|
270
|
-
#
|
271
|
-
module Vision
|
272
|
-
class << self
|
273
|
-
##
|
274
|
-
# The default max results to return for facial detection requests. This is
|
275
|
-
# used on {Project#annotate} as well as {Image#faces}.
|
276
|
-
#
|
277
|
-
# The default value is `100`.
|
278
|
-
#
|
279
|
-
# @example Using the default setting on {Project#annotate}:
|
280
|
-
# require "gcloud"
|
281
|
-
#
|
282
|
-
# gcloud = Gcloud.new
|
283
|
-
# vision = gcloud.vision
|
284
|
-
#
|
285
|
-
# Gcloud::Vision.default_max_faces #=> 100
|
286
|
-
#
|
287
|
-
# annotation = vision.annotate "path/to/faces.jpg", faces: true
|
288
|
-
# # This is the same as calling
|
289
|
-
# # annotation = vision.annotate "path/to/faces.jpg", faces: 100
|
290
|
-
#
|
291
|
-
# @example Updating the default setting on {Project#annotate}:
|
292
|
-
# require "gcloud"
|
293
|
-
#
|
294
|
-
# gcloud = Gcloud.new
|
295
|
-
# vision = gcloud.vision
|
296
|
-
#
|
297
|
-
# # Set a new default
|
298
|
-
# Gcloud::Vision.default_max_faces = 5
|
299
|
-
#
|
300
|
-
# annotation = vision.annotate "path/to/faces.jpg", faces: true
|
301
|
-
# # This is the same as calling
|
302
|
-
# # annotation = vision.annotate "path/to/faces.jpg", faces: 5
|
303
|
-
#
|
304
|
-
#
|
305
|
-
# @example Using the default setting on {Image#faces}:
|
306
|
-
# require "gcloud"
|
307
|
-
#
|
308
|
-
# gcloud = Gcloud.new
|
309
|
-
# vision = gcloud.vision
|
310
|
-
#
|
311
|
-
# Gcloud::Vision.default_max_faces #=> 100
|
312
|
-
#
|
313
|
-
# faces = vision.image("path/to/faces.jpg").faces
|
314
|
-
# # This is the same as calling
|
315
|
-
# # faces = vision.image("path/to/faces.jpg").faces 100
|
316
|
-
#
|
317
|
-
# @example Updating the default setting on {Image#faces}:
|
318
|
-
# require "gcloud"
|
319
|
-
#
|
320
|
-
# gcloud = Gcloud.new
|
321
|
-
# vision = gcloud.vision
|
322
|
-
#
|
323
|
-
# # Set a new default
|
324
|
-
# Gcloud::Vision.default_max_faces = 5
|
325
|
-
#
|
326
|
-
# faces = vision.image("path/to/faces.jpg").faces
|
327
|
-
# # This is the same as calling
|
328
|
-
# # faces = vision.image("path/to/faces.jpg").faces 5
|
329
|
-
#
|
330
|
-
attr_accessor :default_max_faces
|
331
|
-
|
332
|
-
##
|
333
|
-
# The default max results to return for landmark detection requests. This
|
334
|
-
# is used on {Project#annotate} as well as {Image#landmarks}.
|
335
|
-
#
|
336
|
-
# The default value is 100.
|
337
|
-
#
|
338
|
-
# @example Using the default setting on {Project#annotate}:
|
339
|
-
# require "gcloud"
|
340
|
-
#
|
341
|
-
# gcloud = Gcloud.new
|
342
|
-
# vision = gcloud.vision
|
343
|
-
#
|
344
|
-
# Gcloud::Vision.default_max_landmarks #=> 100
|
345
|
-
#
|
346
|
-
# annotation = vision.annotate "path/to/landmarks.jpg", landmarks: true
|
347
|
-
# # This is the same as calling
|
348
|
-
# # annotation = vision.annotate "path/to/landmarks.jpg", landmarks: 100
|
349
|
-
#
|
350
|
-
# @example Updating the default setting on {Project#annotate}:
|
351
|
-
# require "gcloud"
|
352
|
-
#
|
353
|
-
# gcloud = Gcloud.new
|
354
|
-
# vision = gcloud.vision
|
355
|
-
#
|
356
|
-
# # Set a new default
|
357
|
-
# Gcloud::Vision.default_max_landmarks = 5
|
358
|
-
#
|
359
|
-
# annotation = vision.annotate "path/to/landmarks.jpg", landmarks: true
|
360
|
-
# # This is the same as calling
|
361
|
-
# # annotation = vision.annotate "path/to/landmarks.jpg", landmarks: 5
|
362
|
-
#
|
363
|
-
#
|
364
|
-
# @example Using the default setting on {Image#landmarks}:
|
365
|
-
# require "gcloud"
|
366
|
-
#
|
367
|
-
# gcloud = Gcloud.new
|
368
|
-
# vision = gcloud.vision
|
369
|
-
#
|
370
|
-
# Gcloud::Vision.default_max_landmarks #=> 100
|
371
|
-
#
|
372
|
-
# landmarks = vision.image("path/to/landmarks.jpg").landmarks
|
373
|
-
# # This is the same as calling
|
374
|
-
# # landmarks = vision.image("path/to/landmarks.jpg").landmarks 100
|
375
|
-
#
|
376
|
-
# @example Updating the default setting on {Image#landmarks}:
|
377
|
-
# require "gcloud"
|
378
|
-
#
|
379
|
-
# gcloud = Gcloud.new
|
380
|
-
# vision = gcloud.vision
|
381
|
-
#
|
382
|
-
# # Set a new default
|
383
|
-
# Gcloud::Vision.default_max_landmarks = 5
|
384
|
-
#
|
385
|
-
# landmarks = vision.image("path/to/landmarks.jpg").landmarks
|
386
|
-
# # This is the same as calling
|
387
|
-
# # landmarks = vision.image("path/to/landmarks.jpg").landmarks 5
|
388
|
-
#
|
389
|
-
attr_accessor :default_max_landmarks
|
390
|
-
|
391
|
-
##
|
392
|
-
# The default max results to return for logo detection requests. This is
|
393
|
-
# used on {Project#annotate} as well as {Image#logos}.
|
394
|
-
#
|
395
|
-
# The default value is 100.
|
396
|
-
#
|
397
|
-
# @example Using the default setting on {Project#annotate}:
|
398
|
-
# require "gcloud"
|
399
|
-
#
|
400
|
-
# gcloud = Gcloud.new
|
401
|
-
# vision = gcloud.vision
|
402
|
-
#
|
403
|
-
# Gcloud::Vision.default_max_logos #=> 100
|
404
|
-
#
|
405
|
-
# annotation = vision.annotate "path/to/logos.jpg", logos: true
|
406
|
-
# # This is the same as calling
|
407
|
-
# # annotation = vision.annotate "path/to/logos.jpg", logos: 100
|
408
|
-
#
|
409
|
-
# @example Updating the default setting on {Project#annotate}:
|
410
|
-
# require "gcloud"
|
411
|
-
#
|
412
|
-
# gcloud = Gcloud.new
|
413
|
-
# vision = gcloud.vision
|
414
|
-
#
|
415
|
-
# # Set a new default
|
416
|
-
# Gcloud::Vision.default_max_logos = 5
|
417
|
-
#
|
418
|
-
# annotation = vision.annotate "path/to/logos.jpg", logos: true
|
419
|
-
# # This is the same as calling
|
420
|
-
# # annotation = vision.annotate "path/to/logos.jpg", logos: 5
|
421
|
-
#
|
422
|
-
#
|
423
|
-
# @example Using the default setting on {Image#logos}:
|
424
|
-
# require "gcloud"
|
425
|
-
#
|
426
|
-
# gcloud = Gcloud.new
|
427
|
-
# vision = gcloud.vision
|
428
|
-
#
|
429
|
-
# Gcloud::Vision.default_max_logos #=> 100
|
430
|
-
#
|
431
|
-
# logos = vision.image("path/to/logos.jpg").logos
|
432
|
-
# # This is the same as calling
|
433
|
-
# # logos = vision.image("path/to/logos.jpg").logos 100
|
434
|
-
#
|
435
|
-
# @example Updating the default setting on {Image#logos}:
|
436
|
-
# require "gcloud"
|
437
|
-
#
|
438
|
-
# gcloud = Gcloud.new
|
439
|
-
# vision = gcloud.vision
|
440
|
-
#
|
441
|
-
# # Set a new default
|
442
|
-
# Gcloud::Vision.default_max_logos = 5
|
443
|
-
#
|
444
|
-
# logos = vision.image("path/to/logos.jpg").logos
|
445
|
-
# # This is the same as calling
|
446
|
-
# # logos = vision.image("path/to/logos.jpg").logos 5
|
447
|
-
#
|
448
|
-
attr_accessor :default_max_logos
|
449
|
-
|
450
|
-
##
|
451
|
-
# The default max results to return for label detection requests. This is
|
452
|
-
# used on {Project#annotate} as well as {Image#labels}.
|
453
|
-
#
|
454
|
-
# The default value is 100.
|
455
|
-
#
|
456
|
-
# @example Using the default setting on {Project#annotate}:
|
457
|
-
# require "gcloud"
|
458
|
-
#
|
459
|
-
# gcloud = Gcloud.new
|
460
|
-
# vision = gcloud.vision
|
461
|
-
#
|
462
|
-
# Gcloud::Vision.default_max_labels #=> 100
|
463
|
-
#
|
464
|
-
# annotation = vision.annotate "path/to/labels.jpg", labels: true
|
465
|
-
# # This is the same as calling
|
466
|
-
# # annotation = vision.annotate "path/to/labels.jpg", labels: 100
|
467
|
-
#
|
468
|
-
# @example Updating the default setting on {Project#annotate}:
|
469
|
-
# require "gcloud"
|
470
|
-
#
|
471
|
-
# gcloud = Gcloud.new
|
472
|
-
# vision = gcloud.vision
|
473
|
-
#
|
474
|
-
# # Set a new default
|
475
|
-
# Gcloud::Vision.default_max_labels = 5
|
476
|
-
#
|
477
|
-
# annotation = vision.annotate "path/to/labels.jpg", labels: true
|
478
|
-
# # This is the same as calling
|
479
|
-
# # annotation = vision.annotate "path/to/labels.jpg", labels: 5
|
480
|
-
#
|
481
|
-
#
|
482
|
-
# @example Using the default setting on {Image#labels}:
|
483
|
-
# require "gcloud"
|
484
|
-
#
|
485
|
-
# gcloud = Gcloud.new
|
486
|
-
# vision = gcloud.vision
|
487
|
-
#
|
488
|
-
# Gcloud::Vision.default_max_labels #=> 100
|
489
|
-
#
|
490
|
-
# labels = vision.image("path/to/labels.jpg").labels
|
491
|
-
# # This is the same as calling
|
492
|
-
# # labels = vision.image("path/to/labels.jpg").labels 100
|
493
|
-
#
|
494
|
-
# @example Updating the default setting on {Image#labels}:
|
495
|
-
# require "gcloud"
|
496
|
-
#
|
497
|
-
# gcloud = Gcloud.new
|
498
|
-
# vision = gcloud.vision
|
499
|
-
#
|
500
|
-
# # Set a new default
|
501
|
-
# Gcloud::Vision.default_max_labels = 5
|
502
|
-
#
|
503
|
-
# labels = vision.image("path/to/labels.jpg").labels
|
504
|
-
# # This is the same as calling
|
505
|
-
# # labels = vision.image("path/to/labels.jpg").labels 5
|
506
|
-
#
|
507
|
-
attr_accessor :default_max_labels
|
508
|
-
end
|
509
|
-
|
510
|
-
# Set the default values.
|
511
|
-
# Update the comments documentation when these change.
|
512
|
-
self.default_max_faces = 100
|
513
|
-
self.default_max_landmarks = 100
|
514
|
-
self.default_max_logos = 100
|
515
|
-
self.default_max_labels = 100
|
516
|
-
end
|
517
|
-
end
|
17
|
+
require "google/cloud/vision"
|