gcloud 0.11.0 → 0.12.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.
Files changed (121) hide show
  1. checksums.yaml +8 -8
  2. data/AUTHENTICATION.md +3 -3
  3. data/CHANGELOG.md +92 -0
  4. data/OVERVIEW.md +3 -3
  5. data/lib/gcloud.rb +75 -25
  6. data/lib/gcloud/backoff.rb +5 -1
  7. data/lib/gcloud/bigquery.rb +25 -43
  8. data/lib/gcloud/bigquery/copy_job.rb +13 -13
  9. data/lib/gcloud/bigquery/data.rb +20 -16
  10. data/lib/gcloud/bigquery/dataset.rb +202 -177
  11. data/lib/gcloud/bigquery/dataset/access.rb +118 -104
  12. data/lib/gcloud/bigquery/dataset/list.rb +14 -18
  13. data/lib/gcloud/bigquery/extract_job.rb +12 -12
  14. data/lib/gcloud/bigquery/insert_response.rb +12 -14
  15. data/lib/gcloud/bigquery/job.rb +45 -57
  16. data/lib/gcloud/bigquery/job/list.rb +18 -24
  17. data/lib/gcloud/bigquery/load_job.rb +35 -27
  18. data/lib/gcloud/bigquery/project.rb +53 -73
  19. data/lib/gcloud/bigquery/query_data.rb +28 -35
  20. data/lib/gcloud/bigquery/query_job.rb +18 -18
  21. data/lib/gcloud/bigquery/schema.rb +359 -0
  22. data/lib/gcloud/bigquery/service.rb +506 -0
  23. data/lib/gcloud/bigquery/table.rb +185 -266
  24. data/lib/gcloud/bigquery/table/list.rb +15 -19
  25. data/lib/gcloud/bigquery/view.rb +126 -81
  26. data/lib/gcloud/datastore.rb +39 -27
  27. data/lib/gcloud/datastore/commit.rb +2 -2
  28. data/lib/gcloud/datastore/dataset.rb +8 -19
  29. data/lib/gcloud/datastore/dataset/lookup_results.rb +2 -4
  30. data/lib/gcloud/datastore/dataset/query_results.rb +0 -2
  31. data/lib/gcloud/datastore/entity.rb +7 -1
  32. data/lib/gcloud/datastore/errors.rb +5 -27
  33. data/lib/gcloud/datastore/grpc_utils.rb +4 -3
  34. data/lib/gcloud/datastore/key.rb +6 -0
  35. data/lib/gcloud/datastore/service.rb +18 -12
  36. data/lib/gcloud/datastore/transaction.rb +0 -10
  37. data/lib/gcloud/dns.rb +29 -19
  38. data/lib/gcloud/dns/change.rb +10 -15
  39. data/lib/gcloud/dns/change/list.rb +4 -4
  40. data/lib/gcloud/dns/importer.rb +1 -1
  41. data/lib/gcloud/dns/project.rb +32 -49
  42. data/lib/gcloud/dns/record.rb +8 -2
  43. data/lib/gcloud/dns/record/list.rb +4 -4
  44. data/lib/gcloud/dns/service.rb +167 -0
  45. data/lib/gcloud/dns/zone.rb +33 -52
  46. data/lib/gcloud/dns/zone/list.rb +12 -16
  47. data/lib/gcloud/errors.rb +31 -19
  48. data/lib/gcloud/logging.rb +50 -39
  49. data/lib/gcloud/logging/entry.rb +197 -24
  50. data/lib/gcloud/logging/entry/list.rb +0 -2
  51. data/lib/gcloud/logging/logger.rb +1 -1
  52. data/lib/gcloud/logging/metric.rb +3 -9
  53. data/lib/gcloud/logging/metric/list.rb +0 -2
  54. data/lib/gcloud/logging/project.rb +58 -54
  55. data/lib/gcloud/logging/resource_descriptor.rb +2 -2
  56. data/lib/gcloud/logging/resource_descriptor/list.rb +0 -2
  57. data/lib/gcloud/logging/service.rb +32 -23
  58. data/lib/gcloud/logging/sink.rb +8 -14
  59. data/lib/gcloud/logging/sink/list.rb +0 -2
  60. data/lib/gcloud/pubsub.rb +21 -16
  61. data/lib/gcloud/pubsub/policy.rb +204 -0
  62. data/lib/gcloud/pubsub/project.rb +26 -38
  63. data/lib/gcloud/pubsub/service.rb +39 -31
  64. data/lib/gcloud/pubsub/subscription.rb +56 -59
  65. data/lib/gcloud/pubsub/subscription/list.rb +4 -4
  66. data/lib/gcloud/pubsub/topic.rb +69 -66
  67. data/lib/gcloud/pubsub/topic/list.rb +0 -2
  68. data/lib/gcloud/pubsub/topic/{batch.rb → publisher.rb} +15 -2
  69. data/lib/gcloud/resource_manager.rb +27 -26
  70. data/lib/gcloud/resource_manager/manager.rb +19 -39
  71. data/lib/gcloud/resource_manager/policy.rb +211 -0
  72. data/lib/gcloud/resource_manager/project.rb +97 -121
  73. data/lib/gcloud/resource_manager/project/list.rb +7 -7
  74. data/lib/gcloud/resource_manager/project/updater.rb +4 -9
  75. data/lib/gcloud/resource_manager/service.rb +127 -0
  76. data/lib/gcloud/storage.rb +24 -42
  77. data/lib/gcloud/storage/bucket.rb +104 -192
  78. data/lib/gcloud/storage/bucket/acl.rb +47 -143
  79. data/lib/gcloud/storage/bucket/cors.rb +55 -11
  80. data/lib/gcloud/storage/bucket/list.rb +14 -14
  81. data/lib/gcloud/storage/errors.rb +3 -43
  82. data/lib/gcloud/storage/file.rb +114 -111
  83. data/lib/gcloud/storage/file/acl.rb +27 -113
  84. data/lib/gcloud/storage/file/list.rb +21 -21
  85. data/lib/gcloud/storage/project.rb +49 -59
  86. data/lib/gcloud/storage/service.rb +347 -0
  87. data/lib/gcloud/translate.rb +24 -14
  88. data/lib/gcloud/translate/api.rb +12 -21
  89. data/lib/gcloud/translate/detection.rb +5 -5
  90. data/lib/gcloud/translate/language.rb +1 -1
  91. data/lib/gcloud/translate/service.rb +80 -0
  92. data/lib/gcloud/translate/translation.rb +6 -6
  93. data/lib/gcloud/version.rb +1 -1
  94. data/lib/gcloud/vision.rb +24 -15
  95. data/lib/gcloud/vision/annotate.rb +24 -21
  96. data/lib/gcloud/vision/annotation.rb +9 -9
  97. data/lib/gcloud/vision/annotation/entity.rb +11 -11
  98. data/lib/gcloud/vision/annotation/face.rb +25 -25
  99. data/lib/gcloud/vision/annotation/properties.rb +8 -8
  100. data/lib/gcloud/vision/annotation/safe_search.rb +4 -4
  101. data/lib/gcloud/vision/annotation/text.rb +7 -7
  102. data/lib/gcloud/vision/annotation/vertex.rb +1 -1
  103. data/lib/gcloud/vision/image.rb +11 -11
  104. data/lib/gcloud/vision/location.rb +5 -2
  105. data/lib/gcloud/vision/project.rb +14 -16
  106. data/lib/gcloud/vision/service.rb +66 -0
  107. data/lib/google/api_client.rb +0 -0
  108. metadata +27 -24
  109. data/lib/gcloud/bigquery/connection.rb +0 -624
  110. data/lib/gcloud/bigquery/errors.rb +0 -68
  111. data/lib/gcloud/bigquery/table/schema.rb +0 -234
  112. data/lib/gcloud/dns/connection.rb +0 -173
  113. data/lib/gcloud/dns/errors.rb +0 -68
  114. data/lib/gcloud/resource_manager/connection.rb +0 -134
  115. data/lib/gcloud/resource_manager/errors.rb +0 -68
  116. data/lib/gcloud/storage/connection.rb +0 -444
  117. data/lib/gcloud/translate/connection.rb +0 -85
  118. data/lib/gcloud/translate/errors.rb +0 -68
  119. data/lib/gcloud/upload.rb +0 -95
  120. data/lib/gcloud/vision/connection.rb +0 -63
  121. data/lib/gcloud/vision/errors.rb +0 -69
@@ -30,6 +30,9 @@ module Gcloud
30
30
  # keys](https://cloud.google.com/translate/v2/using_rest#creating-server-api-keys).
31
31
  #
32
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.
33
36
  #
34
37
  # @return [Gcloud::Translate::Api]
35
38
  #
@@ -51,8 +54,16 @@ module Gcloud
51
54
  # translation = translate.translate "Hello world!", to: "la"
52
55
  # translation.text #=> "Salve mundi!"
53
56
  #
54
- def self.translate key = nil
55
- Gcloud::Translate::Api.new key
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))
56
67
  end
57
68
 
58
69
  ##
@@ -231,24 +242,23 @@ module Gcloud
231
242
  # languages[0].name #=> "Afrikaans"
232
243
  # ```
233
244
  #
234
- # ## Configuring Backoff
245
+ # ## Configuring retries and timeout
235
246
  #
236
- # The {Gcloud::Backoff} class allows users to globally configure how Cloud API
237
- # requests are automatically retried in the case of some errors, such as a
238
- # `500` or `503` status code, or a specific internal error code such as
239
- # `rateLimitExceeded`.
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.
240
254
  #
241
- # If an API call fails, the response will be inspected to see if the call
242
- # should be retried. If the response matches the criteria, then the request
243
- # will be retried after a delay. If another error occurs, the delay will be
244
- # increased incrementally before a subsequent attempt. The first retry will be
245
- # delayed one second, the second retry two seconds, and so on.
255
+ # You can also set the request `timeout` value in seconds.
246
256
  #
247
257
  # ```ruby
248
258
  # require "gcloud"
249
- # require "gcloud/backoff"
250
259
  #
251
- # Gcloud::Backoff.retries = 5 # Raise the maximum number of retries from 3
260
+ # gcloud = Gcloud.new
261
+ # translate = gcloud.translate retries: 10, timeout: 120
252
262
  # ```
253
263
  #
254
264
  module Translate
@@ -13,11 +13,10 @@
13
13
  # limitations under the License.
14
14
 
15
15
 
16
- require "gcloud/translate/connection"
16
+ require "gcloud/translate/service"
17
17
  require "gcloud/translate/translation"
18
18
  require "gcloud/translate/detection"
19
19
  require "gcloud/translate/language"
20
- require "gcloud/translate/errors"
21
20
 
22
21
  module Gcloud
23
22
  module Translate
@@ -52,20 +51,15 @@ module Gcloud
52
51
  #
53
52
  class Api
54
53
  ##
55
- # @private The Connection object.
56
- attr_accessor :connection
54
+ # @private The Service object.
55
+ attr_accessor :service
57
56
 
58
57
  ##
59
58
  # @private Creates a new Translate Api instance.
60
59
  #
61
60
  # See {Gcloud.translate}
62
- def initialize key
63
- key ||= ENV["TRANSLATE_KEY"]
64
- if key.nil?
65
- key_mising_msg = "An API key is required to use the Translate API."
66
- fail ArgumentError, key_mising_msg
67
- end
68
- @connection = Connection.new key
61
+ def initialize service
62
+ @service = service
69
63
  end
70
64
 
71
65
  ##
@@ -149,10 +143,9 @@ module Gcloud
149
143
  from = from.to_s if from
150
144
  format = format.to_s if format
151
145
  text = Array(text).flatten
152
- resp = connection.translate(text, to: to, from: from,
153
- format: format, cid: cid)
154
- fail ApiError.from_response(resp) unless resp.success?
155
- Translation.from_response resp, text, to, from
146
+ gapi = service.translate text, to: to, from: from,
147
+ format: format, cid: cid
148
+ Translation.from_gapi_list gapi, text, to, from
156
149
  end
157
150
 
158
151
  ##
@@ -196,9 +189,8 @@ module Gcloud
196
189
  def detect *text
197
190
  return nil if text.empty?
198
191
  text = Array(text).flatten
199
- resp = connection.detect(text)
200
- fail ApiError.from_response(resp) unless resp.success?
201
- Detection.from_response resp, text
192
+ gapi = service.detect(text)
193
+ Detection.from_gapi gapi, text
202
194
  end
203
195
 
204
196
  ##
@@ -241,9 +233,8 @@ module Gcloud
241
233
  #
242
234
  def languages language = nil
243
235
  language = language.to_s if language
244
- resp = connection.languages language
245
- fail ApiError.from_response(resp) unless resp.success?
246
- Array(resp.data["languages"]).map { |gapi| Language.from_gapi gapi }
236
+ gapi = service.languages language
237
+ Array(gapi.languages).map { |g| Language.from_gapi g }
247
238
  end
248
239
  end
249
240
  end
@@ -84,11 +84,11 @@ module Gcloud
84
84
  end
85
85
 
86
86
  ##
87
- # @private New Detection from a DetectionsListResponse object as
87
+ # @private New Detection from a ListDetectionsResponse object as
88
88
  # defined by the Google API Client object.
89
- def self.from_response resp, text
90
- res = text.zip(Array(resp.data.detections)).map do |txt, gapi_list|
91
- results = gapi_list.map { |gapi| Result.from_gapi gapi }
89
+ def self.from_gapi gapi, text
90
+ res = text.zip(Array(gapi.detections)).map do |txt, detections_gapi|
91
+ results = detections_gapi.map { |g| Result.from_gapi g }
92
92
  new txt, results
93
93
  end
94
94
  return res.first if res.size == 1
@@ -129,7 +129,7 @@ module Gcloud
129
129
  # @private New Detection::Result from a DetectionsResource object as
130
130
  # defined by the Google API Client object.
131
131
  def self.from_gapi gapi
132
- new gapi["confidence"], gapi["language"]
132
+ new gapi.confidence, gapi.language
133
133
  end
134
134
  end
135
135
  end
@@ -62,7 +62,7 @@ module Gcloud
62
62
  # @private New Language from a LanguagesResource object as defined by the
63
63
  # Google API Client object.
64
64
  def self.from_gapi gapi
65
- new gapi["language"], gapi["name"]
65
+ new gapi.language, gapi.name
66
66
  end
67
67
  end
68
68
  end
@@ -0,0 +1,80 @@
1
+ # Copyright 2016 Google Inc. All rights reserved.
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
+
16
+ require "gcloud/version"
17
+ require "gcloud/errors"
18
+ require "google/apis/translate_v2"
19
+
20
+ module Gcloud
21
+ module Translate
22
+ ##
23
+ # @private
24
+ # Represents the service to Translate, exposing the API calls.
25
+ class Service
26
+ ##
27
+ # Alias to the Google Client API module
28
+ API = Google::Apis::TranslateV2
29
+
30
+ attr_accessor :credentials
31
+
32
+ ##
33
+ # Creates a new Service instance.
34
+ def initialize key, retries: nil, timeout: nil
35
+ @service = API::TranslateService.new
36
+ @service.client_options.application_name = "gcloud-ruby"
37
+ @service.client_options.application_version = Gcloud::VERSION
38
+ @service.request_options.retries = retries || 3
39
+ @service.request_options.timeout_sec = timeout if timeout
40
+ @service.authorization = nil
41
+ @service.key = key
42
+ end
43
+
44
+ def service
45
+ return mocked_service if mocked_service
46
+ @service
47
+ end
48
+ attr_accessor :mocked_service
49
+
50
+ ##
51
+ # Returns API::ListTranslationsResponse
52
+ def translate text, to: nil, from: nil, format: nil, cid: nil
53
+ service.list_translations Array(text), to, cid: cid, format: format,
54
+ source: from
55
+ rescue Google::Apis::Error => e
56
+ raise Gcloud::Error.from_error(e)
57
+ end
58
+
59
+ ##
60
+ # Returns API::ListDetectionsResponse
61
+ def detect text
62
+ service.list_detections Array(text)
63
+ rescue Google::Apis::Error => e
64
+ raise Gcloud::Error.from_error(e)
65
+ end
66
+
67
+ ##
68
+ # Returns API::ListLanguagesResponse
69
+ def languages language = nil
70
+ service.list_languages target: language
71
+ rescue Google::Apis::Error => e
72
+ raise Gcloud::Error.from_error(e)
73
+ end
74
+
75
+ def inspect
76
+ "#{self.class}"
77
+ end
78
+ end
79
+ end
80
+ end
@@ -91,9 +91,9 @@ module Gcloud
91
91
  ##
92
92
  # @private New Translation from a TranslationsListResponse object as
93
93
  # defined by the Google API Client object.
94
- def self.from_response resp, text, to, from
95
- res = text.zip(Array(resp.data["translations"])).map do |origin, gapi|
96
- from_gapi gapi, to, origin, from
94
+ def self.from_gapi_list gapi, text, to, from
95
+ res = text.zip(Array(gapi.translations)).map do |origin, g|
96
+ from_gapi g, to, origin, from
97
97
  end
98
98
  return res.first if res.size == 1
99
99
  res
@@ -103,9 +103,9 @@ module Gcloud
103
103
  # @private New Translation from a TranslationsResource object as defined
104
104
  # by the Google API Client object.
105
105
  def self.from_gapi gapi, to, origin, from
106
- from ||= gapi["detectedSourceLanguage"]
107
- detected = !gapi["detectedSourceLanguage"].nil?
108
- new gapi["translatedText"], to, origin, from, detected
106
+ from ||= gapi.detected_source_language
107
+ detected = !gapi.detected_source_language.nil?
108
+ new gapi.translated_text, to, origin, from, detected
109
109
  end
110
110
  end
111
111
  end
@@ -14,5 +14,5 @@
14
14
 
15
15
 
16
16
  module Gcloud
17
- VERSION = "0.11.0"
17
+ VERSION = "0.12.0"
18
18
  end
data/lib/gcloud/vision.rb CHANGED
@@ -33,6 +33,9 @@ module Gcloud
33
33
  # The default scope is:
34
34
  #
35
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.
36
39
  #
37
40
  # @return [Gcloud::Vision::Project]
38
41
  #
@@ -47,14 +50,21 @@ module Gcloud
47
50
  # landmark = image.landmark
48
51
  # landmark.description #=> "Mount Rushmore"
49
52
  #
50
- def self.vision project = nil, keyfile = nil, scope: nil
53
+ def self.vision project = nil, keyfile = nil, scope: nil, retries: nil,
54
+ timeout: nil
51
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
+
52
59
  if keyfile.nil?
53
60
  credentials = Gcloud::Vision::Credentials.default scope: scope
54
61
  else
55
62
  credentials = Gcloud::Vision::Credentials.new keyfile, scope: scope
56
63
  end
57
- Gcloud::Vision::Project.new project, credentials
64
+
65
+ Gcloud::Vision::Project.new(
66
+ Gcloud::Vision::Service.new(
67
+ project, credentials, retries: retries, timeout: timeout))
58
68
  end
59
69
 
60
70
  ##
@@ -68,7 +78,7 @@ module Gcloud
68
78
  # For more information about Cloud Vision, read the [Google Cloud Vision API
69
79
  # Documentation](https://cloud.google.com/vision/docs/).
70
80
  #
71
- # Gcloud's goal is to provide an API that is familiar and comfortable to
81
+ # The goal of gcloud-ruby is to provide an API that is comfortable to
72
82
  # Rubyists. Authentication is handled by {Gcloud#vision}. You can provide the
73
83
  # project and credential information to connect to the Cloud Vision service,
74
84
  # or if you are running on Google Compute Engine this configuration is taken
@@ -239,24 +249,23 @@ module Gcloud
239
249
  # annotation = vision.annotate image, faces: 5
240
250
  # ```
241
251
  #
242
- # ## Configuring Backoff
252
+ # ## Configuring retries and timeout
243
253
  #
244
- # The {Gcloud::Backoff} class allows users to globally configure how Cloud API
245
- # requests are automatically retried in the case of some errors, such as a
246
- # `500` or `503` status code, or a specific internal error code such as
247
- # `rateLimitExceeded`.
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.
248
261
  #
249
- # If an API call fails, the response will be inspected to see if the call
250
- # should be retried. If the response matches the criteria, then the request
251
- # will be retried after a delay. If another error occurs, the delay will be
252
- # increased incrementally before a subsequent attempt. The first retry will be
253
- # delayed one second, the second retry two seconds, and so on.
262
+ # You can also set the request `timeout` value in seconds.
254
263
  #
255
264
  # ```ruby
256
265
  # require "gcloud"
257
- # require "gcloud/backoff"
258
266
  #
259
- # Gcloud::Backoff.retries = 5 # Raise the maximum number of retries from 3
267
+ # gcloud = Gcloud.new
268
+ # vision = gcloud.vision retries: 10, timeout: 120
260
269
  # ```
261
270
  #
262
271
  module Vision
@@ -14,6 +14,7 @@
14
14
 
15
15
 
16
16
  require "gcloud/vision/image"
17
+ require "google/apis/vision_v1"
17
18
 
18
19
  module Gcloud
19
20
  module Vision
@@ -154,8 +155,11 @@ module Gcloud
154
155
 
155
156
  Array(images).flatten.each do |img|
156
157
  i = image(img)
157
- @requests << { image: i.to_gapi, features: features,
158
- imageContext: i.context.to_gapi }
158
+ @requests << Google::Apis::VisionV1::AnnotateImageRequest.new(
159
+ image: i.to_gapi,
160
+ features: features,
161
+ imageContext: i.context.to_gapi
162
+ )
159
163
  end
160
164
  end
161
165
 
@@ -168,17 +172,20 @@ module Gcloud
168
172
  faces, landmarks, logos, labels)
169
173
 
170
174
  f = []
171
- f << { type: :FACE_DETECTION, maxResults: faces } unless faces.zero?
172
- f << { type: :LANDMARK_DETECTION,
173
- maxResults: landmarks } unless landmarks.zero?
174
- f << { type: :LOGO_DETECTION, maxResults: logos } unless logos.zero?
175
- f << { type: :LABEL_DETECTION, maxResults: labels } unless labels.zero?
176
- f << { type: :TEXT_DETECTION, maxResults: 1 } if text
177
- f << { type: :SAFE_SEARCH_DETECTION, maxResults: 1 } if safe_search
178
- f << { type: :IMAGE_PROPERTIES, maxResults: 1 } if properties
175
+ f << feature("FACE_DETECTION", faces) unless faces.zero?
176
+ f << feature("LANDMARK_DETECTION", landmarks) unless landmarks.zero?
177
+ f << feature("LOGO_DETECTION", logos) unless logos.zero?
178
+ f << feature("LABEL_DETECTION", labels) unless labels.zero?
179
+ f << feature("TEXT_DETECTION", 1) if text
180
+ f << feature("SAFE_SEARCH_DETECTION", 1) if safe_search
181
+ f << feature("IMAGE_PROPERTIES", 1) if properties
179
182
  f
180
183
  end
181
184
 
185
+ def feature type, max_results
186
+ Google::Apis::VisionV1::Feature.new type: type, max_results: max_results
187
+ end
188
+
182
189
  def default_features? faces, landmarks, logos, labels, text,
183
190
  safe_search, properties
184
191
  faces == false && landmarks == false && logos == false &&
@@ -188,17 +195,13 @@ module Gcloud
188
195
 
189
196
  def default_features
190
197
  [
191
- { type: :FACE_DETECTION,
192
- maxResults: Gcloud::Vision.default_max_faces },
193
- { type: :LANDMARK_DETECTION,
194
- maxResults: Gcloud::Vision.default_max_landmarks },
195
- { type: :LOGO_DETECTION,
196
- maxResults: Gcloud::Vision.default_max_logos },
197
- { type: :LABEL_DETECTION,
198
- maxResults: Gcloud::Vision.default_max_labels },
199
- { type: :TEXT_DETECTION, maxResults: 1 },
200
- { type: :SAFE_SEARCH_DETECTION, maxResults: 1 },
201
- { type: :IMAGE_PROPERTIES, maxResults: 1 }
198
+ feature("FACE_DETECTION", Gcloud::Vision.default_max_faces),
199
+ feature("LANDMARK_DETECTION", Gcloud::Vision.default_max_landmarks),
200
+ feature("LOGO_DETECTION", Gcloud::Vision.default_max_logos),
201
+ feature("LABEL_DETECTION", Gcloud::Vision.default_max_labels),
202
+ feature("TEXT_DETECTION", 1),
203
+ feature("SAFE_SEARCH_DETECTION", 1),
204
+ feature("IMAGE_PROPERTIES", 1)
202
205
  ]
203
206
  end
204
207
 
@@ -68,7 +68,7 @@ module Gcloud
68
68
  # face = annotation.faces.first
69
69
  #
70
70
  def faces
71
- @faces ||= Array(@gapi["faceAnnotations"]).map do |fa|
71
+ @faces ||= Array(@gapi.face_annotations).map do |fa|
72
72
  Face.from_gapi fa
73
73
  end
74
74
  end
@@ -128,7 +128,7 @@ module Gcloud
128
128
  # landmark = annotation.landmarks.first
129
129
  #
130
130
  def landmarks
131
- @landmarks ||= Array(@gapi["landmarkAnnotations"]).map do |lm|
131
+ @landmarks ||= Array(@gapi.landmark_annotations).map do |lm|
132
132
  Entity.from_gapi lm
133
133
  end
134
134
  end
@@ -189,7 +189,7 @@ module Gcloud
189
189
  # logo = annotation.logos.first
190
190
  #
191
191
  def logos
192
- @logos ||= Array(@gapi["logoAnnotations"]).map do |lg|
192
+ @logos ||= Array(@gapi.logo_annotations).map do |lg|
193
193
  Entity.from_gapi lg
194
194
  end
195
195
  end
@@ -250,7 +250,7 @@ module Gcloud
250
250
  # label = annotation.labels.first
251
251
  #
252
252
  def labels
253
- @labels ||= Array(@gapi["labelAnnotations"]).map do |lb|
253
+ @labels ||= Array(@gapi.label_annotations).map do |lb|
254
254
  Entity.from_gapi lb
255
255
  end
256
256
  end
@@ -310,7 +310,7 @@ module Gcloud
310
310
  # text = annotation.text
311
311
  #
312
312
  def text
313
- @text ||= Text.from_gapi(@gapi["textAnnotations"])
313
+ @text ||= Text.from_gapi(@gapi.text_annotations)
314
314
  end
315
315
 
316
316
  ##
@@ -348,8 +348,8 @@ module Gcloud
348
348
  # safe_search = annotation.safe_search
349
349
  #
350
350
  def safe_search
351
- return nil unless @gapi["safeSearchAnnotation"]
352
- @safe_search ||= SafeSearch.from_gapi(@gapi["safeSearchAnnotation"])
351
+ return nil unless @gapi.safe_search_annotation
352
+ @safe_search ||= SafeSearch.from_gapi(@gapi.safe_search_annotation)
353
353
  end
354
354
 
355
355
  ##
@@ -388,8 +388,8 @@ module Gcloud
388
388
  # properties = annotation.properties
389
389
  #
390
390
  def properties
391
- return nil unless @gapi["imagePropertiesAnnotation"]
392
- @properties ||= Properties.from_gapi(@gapi["imagePropertiesAnnotation"])
391
+ return nil unless @gapi.image_properties_annotation
392
+ @properties ||= Properties.from_gapi(@gapi.image_properties_annotation)
393
393
  end
394
394
 
395
395
  ##