google-cloud-vision 0.20.2 → 0.21.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
  SHA1:
3
- metadata.gz: 759e9d66fc5ac97bb5ae8c503601c9be1c661a31
4
- data.tar.gz: 970f2c09c96cbe48ae9c1105a73ce50d16fefe0c
3
+ metadata.gz: 327b418796e39bd6b63dcc852e5118650cf14894
4
+ data.tar.gz: 634d89492078f70090e2ef0d90ca956fa56b2a36
5
5
  SHA512:
6
- metadata.gz: 980170fbb90dd2f6bdcdbb1761418975688d4bfd05c5e618b3949f723d57c30e013cd82fcd811bfe638002c732c28acdf74fb21e850aa89c9a0aa1a6091b9c7e
7
- data.tar.gz: 6b69299bdc20150cf0507f8f7a1ac9d0d7da05646fc249d453804e4a40f887b8da101830e5cc02417d329e3a50cac01e20607d181b6837f0230dca53e5895a5b
6
+ metadata.gz: f5ba3495829c5814c14e77df4896d83b0005bf983ad1ad5f693483c1d7aa18c455a8ad2cf43ac86e0b59353448af90a69057496b771380dc33c6261348043e03
7
+ data.tar.gz: fe7cbb4adcd8cb72d9b8e382f3c0f57f70c2a1fc52811c01bf2988e4e01c4c8a7ea9ef03d0b0b171dbefdc22ff4949a8a7067242c1069cfa84739df4bec941a2
@@ -35,9 +35,9 @@ module Google
35
35
  # The default scope is:
36
36
  #
37
37
  # * `https://www.googleapis.com/auth/cloud-platform`
38
- # @param [Integer] retries Number of times to retry requests on server
39
- # error. The default value is `3`. Optional.
40
38
  # @param [Integer] timeout Default timeout to use in requests. Optional.
39
+ # @param [Hash] client_config A hash of values to override the default
40
+ # behavior of the API client. Optional.
41
41
  #
42
42
  # @return [Google::Cloud::Vision::Project]
43
43
  #
@@ -59,10 +59,10 @@ module Google
59
59
  # platform_scope = "https://www.googleapis.com/auth/cloud-platform"
60
60
  # vision = gcloud.vision scope: platform_scope
61
61
  #
62
- def vision scope: nil, retries: nil, timeout: nil
62
+ def vision scope: nil, timeout: nil, client_config: nil
63
63
  Google::Cloud.vision @project, @keyfile, scope: scope,
64
- retries: (retries || @retries),
65
- timeout: (timeout || @timeout)
64
+ timeout: (timeout || @timeout),
65
+ client_config: client_config
66
66
  end
67
67
 
68
68
  ##
@@ -81,40 +81,28 @@ module Google
81
81
  # The default scope is:
82
82
  #
83
83
  # * `https://www.googleapis.com/auth/cloud-platform`
84
- # @param [Integer] retries Number of times to retry requests on server
85
- # error. The default value is `3`. Optional.
86
84
  # @param [Integer] timeout Default timeout to use in requests. Optional.
85
+ # @param [Hash] client_config A hash of values to override the default
86
+ # behavior of the API client. Optional.
87
87
  #
88
88
  # @return [Google::Cloud::Vision::Project]
89
89
  #
90
90
  # @example
91
- # require "google/cloud/vision"
91
+ # require "google/cloud"
92
92
  #
93
- # gcloud = Google::Cloud.new
94
- # vision = gcloud.vision
93
+ # vision = Google::Cloud.vision
95
94
  #
96
95
  # image = vision.image "path/to/landmark.jpg"
97
96
  #
98
97
  # landmark = image.landmark
99
98
  # landmark.description #=> "Mount Rushmore"
100
99
  #
101
- def self.vision project = nil, keyfile = nil, scope: nil, retries: nil,
102
- timeout: nil
100
+ def self.vision project = nil, keyfile = nil, scope: nil, timeout: nil,
101
+ client_config: nil
103
102
  require "google/cloud/vision"
104
- project ||= Google::Cloud::Vision::Project.default_project
105
- project = project.to_s # Always cast to a string
106
- fail ArgumentError, "project is missing" if project.empty?
107
-
108
- if keyfile.nil?
109
- credentials = Google::Cloud::Vision::Credentials.default scope: scope
110
- else
111
- credentials = Google::Cloud::Vision::Credentials.new \
112
- keyfile, scope: scope
113
- end
114
-
115
- Google::Cloud::Vision::Project.new(
116
- Google::Cloud::Vision::Service.new(
117
- project, credentials, retries: retries, timeout: timeout))
103
+ Google::Cloud::Vision.new project: project, keyfile: keyfile,
104
+ scope: scope, timeout: timeout,
105
+ client_config: client_config
118
106
  end
119
107
  end
120
108
  end
@@ -21,10 +21,10 @@ module Google
21
21
  ##
22
22
  # # Google Cloud Vision
23
23
  #
24
- # Google Cloud Vision allows easy integration of vision detection features
25
- # developer applications, including image labeling, face and landmark
26
- # detection, optical character recognition (OCR), and tagging of explicit
27
- # content.
24
+ # Google Cloud Vision allows developers to easily integrate vision
25
+ # detection features within applications, including image labeling, face
26
+ # and landmark detection, optical character recognition (OCR), and tagging
27
+ # of explicit content.
28
28
  #
29
29
  # For more information about Cloud Vision, read the [Google Cloud Vision API
30
30
  # Documentation](https://cloud.google.com/vision/docs/).
@@ -48,17 +48,16 @@ module Google
48
48
  # a request. Reducing your file size can significantly improve throughput;
49
49
  # however, be careful not to reduce image quality in the process. See [Best
50
50
  # Practices - Image
51
- # Sizing](https://cloud.google.com/vision/docs/image-best-practices#image_sizing)
51
+ # Sizing](https://cloud.google.com/vision/docs/best-practices#image_sizing)
52
52
  # for current file size limits.
53
53
  #
54
54
  # Use {Vision::Project#image} to create images for the Cloud Vision service.
55
55
  # You can provide a file path:
56
56
  #
57
57
  # ```ruby
58
- # require "google/cloud"
58
+ # require "google/cloud/vision"
59
59
  #
60
- # gcloud = Google::Cloud.new
61
- # vision = gcloud.vision
60
+ # vision = Google::Cloud::Vision.new
62
61
  #
63
62
  # image = vision.image "path/to/landmark.jpg"
64
63
  # ```
@@ -66,10 +65,9 @@ module Google
66
65
  # Or, you can initialize the image with a Google Cloud Storage URI:
67
66
  #
68
67
  # ```ruby
69
- # require "google/cloud"
68
+ # require "google/cloud/vision"
70
69
  #
71
- # gcloud = Google::Cloud.new
72
- # vision = gcloud.vision
70
+ # vision = Google::Cloud::Vision.new
73
71
  #
74
72
  # image = vision.image "gs://bucket-name/path_to_image_object"
75
73
  # ```
@@ -84,10 +82,9 @@ module Google
84
82
  # {Vision::Project#annotate}, below.)
85
83
  #
86
84
  # ```ruby
87
- # require "google/cloud"
85
+ # require "google/cloud/vision"
88
86
  #
89
- # gcloud = Google::Cloud.new
90
- # vision = gcloud.vision
87
+ # vision = Google::Cloud::Vision.new
91
88
  #
92
89
  # image = vision.image "path/to/face.jpg"
93
90
  #
@@ -104,10 +101,9 @@ module Google
104
101
  # (or a string file path or Storage URI) to {Vision::Project#annotate}:
105
102
  #
106
103
  # ```ruby
107
- # require "google/cloud"
104
+ # require "google/cloud/vision"
108
105
  #
109
- # gcloud = Google::Cloud.new
110
- # vision = gcloud.vision
106
+ # vision = Google::Cloud::Vision.new
111
107
  #
112
108
  # image = vision.image "path/to/face.jpg"
113
109
  #
@@ -120,10 +116,9 @@ module Google
120
116
  # request:
121
117
  #
122
118
  # ```ruby
123
- # require "google/cloud"
119
+ # require "google/cloud/vision"
124
120
  #
125
- # gcloud = Google::Cloud.new
126
- # vision = gcloud.vision
121
+ # vision = Google::Cloud::Vision.new
127
122
  #
128
123
  # face_image = vision.image "path/to/face.jpg"
129
124
  # landmark_image = vision.image "path/to/landmark.jpg"
@@ -147,10 +142,9 @@ module Google
147
142
  # request to the Cloud Vision API:
148
143
  #
149
144
  # ```ruby
150
- # require "google/cloud"
145
+ # require "google/cloud/vision"
151
146
  #
152
- # gcloud = Google::Cloud.new
153
- # vision = gcloud.vision
147
+ # vision = Google::Cloud::Vision.new
154
148
  #
155
149
  # face_image = vision.image "path/to/face.jpg"
156
150
  # landmark_image = vision.image "path/to/landmark.jpg"
@@ -177,10 +171,9 @@ module Google
177
171
  # global defaults, you can update the configuration:
178
172
  #
179
173
  # ```ruby
180
- # require "google/cloud"
174
+ # require "google/cloud/vision"
181
175
  #
182
- # gcloud = Google::Cloud.new
183
- # vision = gcloud.vision
176
+ # vision = Google::Cloud::Vision.new
184
177
  #
185
178
  # Google::Cloud::Vision.default_max_faces = 1
186
179
  #
@@ -192,10 +185,9 @@ module Google
192
185
  # integer instead of a flag:
193
186
  #
194
187
  # ```ruby
195
- # require "google/cloud"
188
+ # require "google/cloud/vision"
196
189
  #
197
- # gcloud = Google::Cloud.new
198
- # vision = gcloud.vision
190
+ # vision = Google::Cloud::Vision.new
199
191
  #
200
192
  # image = vision.image "path/to/face.jpg"
201
193
  #
@@ -205,24 +197,14 @@ module Google
205
197
  # annotation = vision.annotate image, faces: 5
206
198
  # ```
207
199
  #
208
- # ## Configuring retries and timeout
200
+ # ## Configuring timeout
209
201
  #
210
- # You can configure how many times API requests may be automatically
211
- # retried. When an API request fails, the response will be inspected to see
212
- # if the request meets criteria indicating that it may succeed on retry,
213
- # such as `500` and `503` status codes or a specific internal error code
214
- # such as `rateLimitExceeded`. If it meets the criteria, the request will be
215
- # retried after a delay. If another error occurs, the delay will be
216
- # increased before a subsequent attempt, until the `retries` limit is
217
- # reached.
218
- #
219
- # You can also set the request `timeout` value in seconds.
202
+ # You can configure the request `timeout` value in seconds.
220
203
  #
221
204
  # ```ruby
222
- # require "google/cloud"
205
+ # require "google/cloud/vision"
223
206
  #
224
- # gcloud = Google::Cloud.new
225
- # vision = gcloud.vision retries: 10, timeout: 120
207
+ # vision = Google::Cloud::Vision.new timeout: 120
226
208
  # ```
227
209
  #
228
210
  module Vision
@@ -234,10 +216,9 @@ module Google
234
216
  # The default value is `100`.
235
217
  #
236
218
  # @example Using the default setting on {Project#annotate}:
237
- # require "google/cloud"
219
+ # require "google/cloud/vision"
238
220
  #
239
- # gcloud = Google::Cloud.new
240
- # vision = gcloud.vision
221
+ # vision = Google::Cloud::Vision.new
241
222
  #
242
223
  # Google::Cloud::Vision.default_max_faces #=> 100
243
224
  #
@@ -246,10 +227,9 @@ module Google
246
227
  # # annotation = vision.annotate "path/to/faces.jpg", faces: 100
247
228
  #
248
229
  # @example Updating the default setting on {Project#annotate}:
249
- # require "google/cloud"
230
+ # require "google/cloud/vision"
250
231
  #
251
- # gcloud = Google::Cloud.new
252
- # vision = gcloud.vision
232
+ # vision = Google::Cloud::Vision.new
253
233
  #
254
234
  # # Set a new default
255
235
  # Google::Cloud::Vision.default_max_faces = 5
@@ -260,10 +240,9 @@ module Google
260
240
  #
261
241
  #
262
242
  # @example Using the default setting on {Image#faces}:
263
- # require "google/cloud"
243
+ # require "google/cloud/vision"
264
244
  #
265
- # gcloud = Google::Cloud.new
266
- # vision = gcloud.vision
245
+ # vision = Google::Cloud::Vision.new
267
246
  #
268
247
  # Google::Cloud::Vision.default_max_faces #=> 100
269
248
  #
@@ -272,10 +251,9 @@ module Google
272
251
  # # faces = vision.image("path/to/faces.jpg").faces 100
273
252
  #
274
253
  # @example Updating the default setting on {Image#faces}:
275
- # require "google/cloud"
254
+ # require "google/cloud/vision"
276
255
  #
277
- # gcloud = Google::Cloud.new
278
- # vision = gcloud.vision
256
+ # vision = Google::Cloud::Vision.new
279
257
  #
280
258
  # # Set a new default
281
259
  # Google::Cloud::Vision.default_max_faces = 5
@@ -293,10 +271,9 @@ module Google
293
271
  # The default value is 100.
294
272
  #
295
273
  # @example Using the default setting on {Project#annotate}:
296
- # require "google/cloud"
274
+ # require "google/cloud/vision"
297
275
  #
298
- # gcloud = Google::Cloud.new
299
- # vision = gcloud.vision
276
+ # vision = Google::Cloud::Vision.new
300
277
  #
301
278
  # Google::Cloud::Vision.default_max_landmarks #=> 100
302
279
  #
@@ -306,10 +283,9 @@ module Google
306
283
  # # annotation = vision.annotate img, landmarks: 100
307
284
  #
308
285
  # @example Updating the default setting on {Project#annotate}:
309
- # require "google/cloud"
286
+ # require "google/cloud/vision"
310
287
  #
311
- # gcloud = Google::Cloud.new
312
- # vision = gcloud.vision
288
+ # vision = Google::Cloud::Vision.new
313
289
  #
314
290
  # # Set a new default
315
291
  # Google::Cloud::Vision.default_max_landmarks = 5
@@ -321,10 +297,9 @@ module Google
321
297
  #
322
298
  #
323
299
  # @example Using the default setting on {Image#landmarks}:
324
- # require "google/cloud"
300
+ # require "google/cloud/vision"
325
301
  #
326
- # gcloud = Google::Cloud.new
327
- # vision = gcloud.vision
302
+ # vision = Google::Cloud::Vision.new
328
303
  #
329
304
  # Google::Cloud::Vision.default_max_landmarks #=> 100
330
305
  #
@@ -333,10 +308,9 @@ module Google
333
308
  # # landmarks = vision.image("path/to/landmarks.jpg").landmarks 100
334
309
  #
335
310
  # @example Updating the default setting on {Image#landmarks}:
336
- # require "google/cloud"
311
+ # require "google/cloud/vision"
337
312
  #
338
- # gcloud = Google::Cloud.new
339
- # vision = gcloud.vision
313
+ # vision = Google::Cloud::Vision.new
340
314
  #
341
315
  # # Set a new default
342
316
  # Google::Cloud::Vision.default_max_landmarks = 5
@@ -354,10 +328,9 @@ module Google
354
328
  # The default value is 100.
355
329
  #
356
330
  # @example Using the default setting on {Project#annotate}:
357
- # require "google/cloud"
331
+ # require "google/cloud/vision"
358
332
  #
359
- # gcloud = Google::Cloud.new
360
- # vision = gcloud.vision
333
+ # vision = Google::Cloud::Vision.new
361
334
  #
362
335
  # Google::Cloud::Vision.default_max_logos #=> 100
363
336
  #
@@ -366,10 +339,9 @@ module Google
366
339
  # # annotation = vision.annotate "path/to/logos.jpg", logos: 100
367
340
  #
368
341
  # @example Updating the default setting on {Project#annotate}:
369
- # require "google/cloud"
342
+ # require "google/cloud/vision"
370
343
  #
371
- # gcloud = Google::Cloud.new
372
- # vision = gcloud.vision
344
+ # vision = Google::Cloud::Vision.new
373
345
  #
374
346
  # # Set a new default
375
347
  # Google::Cloud::Vision.default_max_logos = 5
@@ -380,10 +352,9 @@ module Google
380
352
  #
381
353
  #
382
354
  # @example Using the default setting on {Image#logos}:
383
- # require "google/cloud"
355
+ # require "google/cloud/vision"
384
356
  #
385
- # gcloud = Google::Cloud.new
386
- # vision = gcloud.vision
357
+ # vision = Google::Cloud::Vision.new
387
358
  #
388
359
  # Google::Cloud::Vision.default_max_logos #=> 100
389
360
  #
@@ -392,10 +363,9 @@ module Google
392
363
  # # logos = vision.image("path/to/logos.jpg").logos 100
393
364
  #
394
365
  # @example Updating the default setting on {Image#logos}:
395
- # require "google/cloud"
366
+ # require "google/cloud/vision"
396
367
  #
397
- # gcloud = Google::Cloud.new
398
- # vision = gcloud.vision
368
+ # vision = Google::Cloud::Vision.new
399
369
  #
400
370
  # # Set a new default
401
371
  # Google::Cloud::Vision.default_max_logos = 5
@@ -413,10 +383,9 @@ module Google
413
383
  # The default value is 100.
414
384
  #
415
385
  # @example Using the default setting on {Project#annotate}:
416
- # require "google/cloud"
386
+ # require "google/cloud/vision"
417
387
  #
418
- # gcloud = Google::Cloud.new
419
- # vision = gcloud.vision
388
+ # vision = Google::Cloud::Vision.new
420
389
  #
421
390
  # Google::Cloud::Vision.default_max_labels #=> 100
422
391
  #
@@ -425,10 +394,9 @@ module Google
425
394
  # # annotation = vision.annotate "path/to/labels.jpg", labels: 100
426
395
  #
427
396
  # @example Updating the default setting on {Project#annotate}:
428
- # require "google/cloud"
397
+ # require "google/cloud/vision"
429
398
  #
430
- # gcloud = Google::Cloud.new
431
- # vision = gcloud.vision
399
+ # vision = Google::Cloud::Vision.new
432
400
  #
433
401
  # # Set a new default
434
402
  # Google::Cloud::Vision.default_max_labels = 5
@@ -439,10 +407,9 @@ module Google
439
407
  #
440
408
  #
441
409
  # @example Using the default setting on {Image#labels}:
442
- # require "google/cloud"
410
+ # require "google/cloud/vision"
443
411
  #
444
- # gcloud = Google::Cloud.new
445
- # vision = gcloud.vision
412
+ # vision = Google::Cloud::Vision.new
446
413
  #
447
414
  # Google::Cloud::Vision.default_max_labels #=> 100
448
415
  #
@@ -451,10 +418,9 @@ module Google
451
418
  # # labels = vision.image("path/to/labels.jpg").labels 100
452
419
  #
453
420
  # @example Updating the default setting on {Image#labels}:
454
- # require "google/cloud"
421
+ # require "google/cloud/vision"
455
422
  #
456
- # gcloud = Google::Cloud.new
457
- # vision = gcloud.vision
423
+ # vision = Google::Cloud::Vision.new
458
424
  #
459
425
  # # Set a new default
460
426
  # Google::Cloud::Vision.default_max_labels = 5
@@ -472,6 +438,57 @@ module Google
472
438
  self.default_max_landmarks = 100
473
439
  self.default_max_logos = 100
474
440
  self.default_max_labels = 100
441
+
442
+ ##
443
+ # Creates a new object for connecting to the Vision service.
444
+ # Each call creates a new connection.
445
+ #
446
+ # @param [String] project Project identifier for the Vision service you
447
+ # are connecting to.
448
+ # @param [String, Hash] keyfile Keyfile downloaded from Google Cloud. If
449
+ # file path the file must be readable.
450
+ # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling
451
+ # the set of resources and operations that the connection can access.
452
+ # See [Using OAuth 2.0 to Access Google
453
+ # APIs](https://developers.google.com/identity/protocols/OAuth2).
454
+ #
455
+ # The default scope is:
456
+ #
457
+ # * `https://www.googleapis.com/auth/cloud-platform`
458
+ # @param [Integer] timeout Default timeout to use in requests. Optional.
459
+ # @param [Hash] client_config A hash of values to override the default
460
+ # behavior of the API client. Optional.
461
+ #
462
+ # @return [Google::Cloud::Vision::Project]
463
+ #
464
+ # @example
465
+ # require "google/cloud/vision"
466
+ #
467
+ # vision = Google::Cloud::Vision.new
468
+ #
469
+ # image = vision.image "path/to/landmark.jpg"
470
+ #
471
+ # landmark = image.landmark
472
+ # landmark.description #=> "Mount Rushmore"
473
+ #
474
+ def self.new project: nil, keyfile: nil, scope: nil, timeout: nil,
475
+ client_config: nil
476
+ project ||= Google::Cloud::Vision::Project.default_project
477
+ project = project.to_s # Always cast to a string
478
+ fail ArgumentError, "project is missing" if project.empty?
479
+
480
+ if keyfile.nil?
481
+ credentials = Google::Cloud::Vision::Credentials.default scope: scope
482
+ else
483
+ credentials = Google::Cloud::Vision::Credentials.new \
484
+ keyfile, scope: scope
485
+ end
486
+
487
+ Google::Cloud::Vision::Project.new(
488
+ Google::Cloud::Vision::Service.new(
489
+ project, credentials, timeout: timeout,
490
+ client_config: client_config))
491
+ end
475
492
  end
476
493
  end
477
494
  end