gcloud 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OGM0OTdkYTJmYjlhOTU0NWFjYjEzZmI2ZGJmZDBhMGQ5NzJhODY1OQ==
4
+ ZDg1NjYxMTkxZjIxYmUzNmMyZGMzNDNlY2Y1MGZiZWYwNWYzZTdjOQ==
5
5
  data.tar.gz: !binary |-
6
- NDgxNGI1OTM3MTMwZGY5ZmQ4NzcxZWZkMjg4YTM2MTg1ZDMyMWRjMw==
6
+ ZDQwZjAxZGRmZmY4MmNlNGE1NmJiMTc3MTFkYWVmODkzNmFkZmU4Yw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTFmYTY4YmRhOWJiMjJmMWU5OWM2YmZmODE1ZGQ0NmQ0MTgyNmExOTdhN2E1
10
- NGU4OTAyODg3NTUwOWM1YzVmYjQwNThmMDdmNmQzYjU0YTA3NGVhOGQ5ZmFk
11
- ZjE1OGFiMDcxZjFmZGFhNzkzMjhmMGIxZGNhYjhmMWQ0YzRlOTU=
9
+ YzkwYWVjYWZhYTJjMjY2NWM0ZWFjYmNkZDI3YzBiZjc4YTcwOTVjYjhkZTBk
10
+ ZmVjMDE4YmQ5Mjc3YmViMzZlNWExOTllMzRmYTE0NTJiMDNkYjI2MDlmMmJk
11
+ OWU0N2UzODJlYWI3NjU5NDAwODQ2MjAzMDZkODAwMjVmYTEzYTk=
12
12
  data.tar.gz: !binary |-
13
- NDQxZmMxNTk5NjAwODA3ZDg5NGM5NjVkZDBmY2Q1OWIxYWM3OGIwNzQ2OTE0
14
- ZDA5MjNlNzgxODMyY2MyNWM3NmJmZGZjZjdhZGJlYTNlZWQ4MmRkNzA2NTk1
15
- OGYxNTVlNjk4ZWUzN2M0YTFkNDY2Yjk3MDY4MTUzNDM1MWVlOTI=
13
+ ZTEzMjg3Y2M5ZTAzNjk5MGRjYzZjOTE2ZGQyZjljOTljYjI2NDczMjhkMTgw
14
+ OWZiZTZiNTg1YjI3ODU3NGY3NzIxMTBjN2Y2YmI1N2IzNTViMjc4MTNhOTFl
15
+ MWZjMzFkZjFkOTM1NDM2YjU4MWM5ODEwNDdmMWJjNDVhOWQ3MGY=
@@ -1,5 +1,22 @@
1
1
  # Release History
2
2
 
3
+ ### 0.10.0 / 2016-05-19
4
+
5
+ #### Major Changes
6
+
7
+ * Add Vision service implementation
8
+
9
+ #### Minor Changes
10
+
11
+ * BigQuery
12
+ * Restore chunk_size argument on Gcloud::Bigquery::Table#load (gramos74)
13
+ * Storage
14
+ * Gcloud::Storage::Bucket#create_file now uses default chunk_size
15
+ * Datastore
16
+ * Fixed documentation (bmclean)
17
+ * Add Gcloud::Upload.default_chunk_size
18
+ * Pegged dependency to google-protobuf version 3.0.0.alpha.5.0.5.1
19
+
3
20
  ### 0.9.0 / 2016-05-11
4
21
 
5
22
  #### Major Changes
@@ -239,3 +239,21 @@ translation.to #=> "la"
239
239
  translation.text #=> "Salve mundi!"
240
240
  ```
241
241
 
242
+ # Vision
243
+
244
+ [Google Cloud Vision](https://cloud.google.com/vision/) ([docs](https://cloud.google.com/vision/docs)) allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content.
245
+
246
+ See the {Gcloud::Vision gcloud-ruby Cloud Vision API documentation} to learn how to connect to Google Cloud Vision using this library.
247
+
248
+ ```ruby
249
+ require "gcloud"
250
+
251
+ gcloud = Gcloud.new
252
+ vision = gcloud.vision
253
+
254
+ image = vision.image "path/to/landmark.jpg"
255
+
256
+ landmark = image.landmark
257
+ landmark.description #=> "Mount Rushmore"
258
+ ```
259
+
@@ -387,4 +387,42 @@ module Gcloud
387
387
  require "gcloud/translate"
388
388
  Gcloud.translate key
389
389
  end
390
+
391
+ ##
392
+ # Creates a new object for connecting to the Vision service.
393
+ # Each call creates a new connection.
394
+ #
395
+ # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
396
+ # set of resources and operations that the connection can access. See [Using
397
+ # OAuth 2.0 to Access Google
398
+ # APIs](https://developers.google.com/identity/protocols/OAuth2).
399
+ #
400
+ # The default scope is:
401
+ #
402
+ # * `https://www.googleapis.com/auth/cloud-platform`
403
+ #
404
+ # @return [Gcloud::Vision::Project]
405
+ #
406
+ # @example
407
+ # require "gcloud"
408
+ #
409
+ # gcloud = Gcloud.new
410
+ # vision = gcloud.vision
411
+ #
412
+ # image = vision.image "path/to/landmark.jpg"
413
+ #
414
+ # landmark = image.landmark
415
+ # landmark.description #=> "Mount Rushmore"
416
+ #
417
+ # @example The default scope can be overridden with the `scope` option:
418
+ # require "gcloud"
419
+ #
420
+ # gcloud = Gcloud.new
421
+ # platform_scope = "https://www.googleapis.com/auth/cloud-platform"
422
+ # vision = gcloud.vision scope: platform_scope
423
+ #
424
+ def vision scope: nil
425
+ require "gcloud/vision"
426
+ Gcloud.vision @project, @keyfile, scope: scope
427
+ end
390
428
  end
@@ -600,6 +600,11 @@ module Gcloud
600
600
  # See [Loading Data with a POST Request](
601
601
  # https://cloud.google.com/bigquery/loading-data-post-request#multipart).
602
602
  #
603
+ # A `chunk_size` value can be provided in the options to be used in
604
+ # resumable uploads. This value is the number of bytes per chunk and must
605
+ # be divisible by 256KB. If it is not divisible by 256KB then it will be
606
+ # lowered to the nearest acceptable value.
607
+ #
603
608
  # @param [File, Gcloud::Storage::File, String] file A file or the URI of a
604
609
  # Google Cloud Storage file containing data to load into the table.
605
610
  # @param [String] format The exported file format. The default value is
@@ -678,6 +683,10 @@ module Gcloud
678
683
  # file that BigQuery will skip when loading the data. The default value
679
684
  # is `0`. This property is useful if you have header rows in the file
680
685
  # that should be skipped.
686
+ # @param [Integer] chunk_size The number of bytes per chunk in a resumable
687
+ # upload. Must be divisible by 256KB. If it is not divisible by 265KB
688
+ # then it will be lowered to the nearest acceptable value. If no value
689
+ # is provided it will use {Gcloud::Upload.default_chunk_size}. Optional.
681
690
  #
682
691
  # @return [Gcloud::Bigquery::LoadJob]
683
692
  #
@@ -748,13 +757,14 @@ module Gcloud
748
757
  def load file, format: nil, create: nil, write: nil,
749
758
  projection_fields: nil, jagged_rows: nil, quoted_newlines: nil,
750
759
  encoding: nil, delimiter: nil, ignore_unknown: nil,
751
- max_bad_records: nil, quote: nil, skip_leading: nil, dryrun: nil
760
+ max_bad_records: nil, quote: nil, skip_leading: nil, dryrun: nil,
761
+ chunk_size: nil
752
762
  ensure_connection!
753
763
  options = { format: format, create: create, write: write,
754
764
  projection_fields: projection_fields,
755
765
  jagged_rows: jagged_rows, quoted_newlines: quoted_newlines,
756
766
  encoding: encoding, delimiter: delimiter,
757
- ignore_unknown: ignore_unknown,
767
+ ignore_unknown: ignore_unknown, chunk_size: chunk_size,
758
768
  max_bad_records: max_bad_records, quote: quote,
759
769
  skip_leading: skip_leading, dryrun: dryrun }
760
770
  return load_storage(file, options) if storage_url? file
@@ -906,7 +916,8 @@ module Gcloud
906
916
  end
907
917
 
908
918
  def load_resumable file, options = {}
909
- chunk_size = verify_chunk_size! options[:chunk_size]
919
+ chunk_size = Gcloud::Upload.verify_chunk_size options[:chunk_size],
920
+ file.length
910
921
  resp = connection.load_resumable table_ref, file, chunk_size, options
911
922
  if resp.success?
912
923
  Job.from_gapi resp.data, connection
@@ -942,18 +953,6 @@ module Gcloud
942
953
  false
943
954
  end
944
955
 
945
- ##
946
- # Determines if a chunk_size is valid.
947
- def verify_chunk_size! chunk_size
948
- chunk_size = chunk_size.to_i
949
- chunk_mod = 256 * 1024 # 256KB
950
- if (chunk_size.to_i % chunk_mod) != 0
951
- chunk_size = (chunk_size / chunk_mod) * chunk_mod
952
- end
953
- return if chunk_size.zero?
954
- chunk_size
955
- end
956
-
957
956
  ##
958
957
  # Load the complete representation of the table if it has been
959
958
  # only partially loaded by a request to the API list method.
@@ -121,11 +121,11 @@ module Gcloud
121
121
  end
122
122
 
123
123
  ##
124
- # Retrieves all log entries by repeatedly loading {#next} until
124
+ # Retrieves all query results by repeatedly loading {#next} until
125
125
  # {#next?} returns `false`. Returns the list instance for method
126
126
  # chaining.
127
127
  #
128
- # This method may make several API calls until all log entries are
128
+ # This method may make several API calls until all query results are
129
129
  # retrieved. Be sure to use as narrow a search criteria as possible.
130
130
  # Please use with caution.
131
131
  #
@@ -133,10 +133,9 @@ module Gcloud
133
133
  # require "gcloud"
134
134
  #
135
135
  # gcloud = Gcloud.new
136
- # logging = gcloud.logging
137
- # hour_ago = (Time.now - 60*60).utc.strftime('%FT%TZ')
138
- # recent_errors = "timestamp >= \"#{hour_ago}\" severity >= ERROR"
139
- # entries = logging.entries(filter: recent_errors).all
136
+ # datastore = gcloud.datastore
137
+ # query = datastore.query("Tasks")
138
+ # all_tasks = datastore.run(query).all
140
139
  #
141
140
  def all
142
141
  while next?
@@ -515,7 +515,8 @@ module Gcloud
515
515
  # response header to be returned when the file is downloaded.
516
516
  # @param [Integer] chunk_size The number of bytes per chunk in a resumable
517
517
  # upload. Must be divisible by 256KB. If it is not divisible by 265KB
518
- # then it will be lowered to the nearest acceptable value.
518
+ # then it will be lowered to the nearest acceptable value. If no value
519
+ # is provided it will use {Gcloud::Upload.default_chunk_size}. Optional.
519
520
  # @param [String] crc32c The CRC32c checksum of the file data, as
520
521
  # described in [RFC 4960, Appendix
521
522
  # B](http://tools.ietf.org/html/rfc4960#appendix-B).
@@ -16,6 +16,7 @@
16
16
  require "pathname"
17
17
  require "gcloud/version"
18
18
  require "gcloud/backoff"
19
+ require "gcloud/upload"
19
20
  require "google/api_client"
20
21
  require "mime/types"
21
22
 
@@ -382,8 +383,9 @@ module Gcloud
382
383
  def file_media local_path, options, resumable
383
384
  media = Google::APIClient::UploadIO.new local_path,
384
385
  options[:content_type]
385
- return media unless resumable && options[:chunk_size]
386
- media.chunk_size = verify_chunk_size!(options.delete(:chunk_size))
386
+ return media unless resumable
387
+ media.chunk_size = Gcloud::Upload.verify_chunk_size(
388
+ options.delete(:chunk_size), media.length)
387
389
  media
388
390
  end
389
391
 
@@ -413,18 +415,6 @@ module Gcloud
413
415
  yield
414
416
  end
415
417
  end
416
-
417
- ##
418
- # Determines if a chunk_size is valid.
419
- def verify_chunk_size! chunk_size
420
- chunk_size = chunk_size.to_i
421
- chunk_mod = 256 * 1024 # 256KB
422
- if (chunk_size.to_i % chunk_mod) != 0
423
- chunk_size = (chunk_size / chunk_mod) * chunk_mod
424
- end
425
- return if chunk_size.zero?
426
- chunk_size
427
- end
428
418
  end
429
419
  end
430
420
  end
@@ -40,12 +40,56 @@ module Gcloud
40
40
  end
41
41
 
42
42
  ##
43
- # Sets a new resumable threshold value.
43
+ # Sets a new resumable threshold value in number of bytes.
44
44
  def self.resumable_threshold= new_resumable_threshold
45
45
  @@resumable_threshold = new_resumable_threshold.to_i
46
46
  end
47
47
 
48
- # Set the default threshold to 5 MiB.
49
- self.resumable_threshold = 5_000_000
48
+ ##
49
+ # Default chunk size used on resumable uploads.
50
+ #
51
+ # The default value is 10 MB (10,485,760 bytes).
52
+ def self.default_chunk_size
53
+ @@default_chunk_size
54
+ end
55
+
56
+ ##
57
+ # Sets a new default chunk_size value in number of bytes. Must be a multiple
58
+ # of 256KB (262,144).
59
+ def self.default_chunk_size= new_chunk_size
60
+ new_chunk_size = normalize_chunk_size new_chunk_size
61
+ @@default_chunk_size = new_chunk_size if new_chunk_size
62
+ end
63
+
64
+ ##
65
+ # @private Determines if a chunk_size is valid. Must be a multiple of 256KB.
66
+ # Returns lowest possible chunk_size if given a very small value.
67
+ def self.normalize_chunk_size chunk_size
68
+ chunk_size = chunk_size.to_i
69
+ chunk_mod = 256 * 1024 # 256KB
70
+ if (chunk_size.to_i % chunk_mod) != 0
71
+ chunk_size = (chunk_size / chunk_mod) * chunk_mod
72
+ end
73
+ return chunk_mod if chunk_size.zero?
74
+ chunk_size
75
+ end
76
+
77
+ ##
78
+ # @private Determines if a chunk_size is valid. Must be a multiple of 256KB.
79
+ # Returns the default chunk_size if one is not provided.
80
+ def self.verify_chunk_size chunk_size, file_size
81
+ if chunk_size.to_i.zero?
82
+ return nil if file_size < default_chunk_size
83
+ return default_chunk_size
84
+ else
85
+ chunk_size = normalize_chunk_size chunk_size
86
+ return nil if file_size < chunk_size
87
+ return chunk_size
88
+ end
89
+ end
90
+
91
+ # Set the default values for threshold and chunk_size.
92
+ self.resumable_threshold = 5_000_000 # 5 MiB
93
+ self.default_chunk_size = 10_485_760 # 10 MB
50
94
  end
51
95
  end
@@ -14,5 +14,5 @@
14
14
 
15
15
 
16
16
  module Gcloud
17
- VERSION = "0.9.0"
17
+ VERSION = "0.10.0"
18
18
  end
@@ -0,0 +1,488 @@
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"
17
+ require "gcloud/vision/project"
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
+ #
37
+ # @return [Gcloud::Vision::Project]
38
+ #
39
+ # @example
40
+ # require "gcloud/vision"
41
+ #
42
+ # gcloud = Gcloud.new
43
+ # vision = gcloud.vision
44
+ #
45
+ # image = vision.image "path/to/landmark.jpg"
46
+ #
47
+ # landmark = image.landmark
48
+ # landmark.description #=> "Mount Rushmore"
49
+ #
50
+ def self.vision project = nil, keyfile = nil, scope: nil
51
+ project ||= Gcloud::Vision::Project.default_project
52
+ if keyfile.nil?
53
+ credentials = Gcloud::Vision::Credentials.default scope: scope
54
+ else
55
+ credentials = Gcloud::Vision::Credentials.new keyfile, scope: scope
56
+ end
57
+ Gcloud::Vision::Project.new project, credentials
58
+ end
59
+
60
+ ##
61
+ # # Google Cloud Vision
62
+ #
63
+ # Google Cloud Vision allows easy integration of vision detection features
64
+ # developer applications, including image labeling, face and landmark
65
+ # detection, optical character recognition (OCR), and tagging of explicit
66
+ # content.
67
+ #
68
+ # For more information about Cloud Vision, read the [Google Cloud Vision API
69
+ # Documentation](https://cloud.google.com/vision/docs/).
70
+ #
71
+ # Gcloud's goal is to provide an API that is familiar and comfortable to
72
+ # Rubyists. Authentication is handled by {Gcloud#vision}. You can provide the
73
+ # project and credential information to connect to the Cloud Vision service,
74
+ # or if you are running on Google Compute Engine this configuration is taken
75
+ # care of for you. You can read more about the options for connecting in the
76
+ # [Authentication
77
+ # Guide](https://googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).
78
+ #
79
+ # ## Creating images
80
+ #
81
+ # The Cloud Vision API supports a variety of image file formats, including
82
+ # JPEG, PNG8, PNG24, Animated GIF (first frame only), and RAW. See [Best
83
+ # Practices - Image Types](https://cloud.google.com/vision/docs/image-best-practices#image_types)
84
+ # for the complete list of formats. Be aware that Cloud Vision sets upper
85
+ # limits on file size as well as on the total combined size of all images in a
86
+ # request. Reducing your file size can significantly improve throughput;
87
+ # however, be careful not to reduce image quality in the process. See [Best
88
+ # Practices - Image Sizing](https://cloud.google.com/vision/docs/image-best-practices#image_sizing)
89
+ # for current file size limits.
90
+ #
91
+ # Use {Vision::Project#image} to create images for the Cloud Vision service.
92
+ # You can provide a file path:
93
+ #
94
+ # ```ruby
95
+ # require "gcloud"
96
+ #
97
+ # gcloud = Gcloud.new
98
+ # vision = gcloud.vision
99
+ #
100
+ # image = vision.image "path/to/landmark.jpg"
101
+ # ```
102
+ #
103
+ # Or, you can initialize the image with a Google Cloud Storage URI:
104
+ #
105
+ # ```ruby
106
+ # require "gcloud"
107
+ #
108
+ # gcloud = Gcloud.new
109
+ # vision = gcloud.vision
110
+ #
111
+ # image = vision.image "gs://bucket-name/path_to_image_object"
112
+ # ```
113
+ #
114
+ # Creating an Image instance does not perform an API request.
115
+ #
116
+ # ## Annotating images
117
+ #
118
+ # The instance methods on {Vision::Image} invoke Cloud Vision's detection
119
+ # features individually. Each method call makes an API request. (If you want
120
+ # to run multiple features in a single request, see the examples for
121
+ # {Vision::Project#annotate}, below.)
122
+ #
123
+ # ```ruby
124
+ # require "gcloud"
125
+ #
126
+ # gcloud = Gcloud.new
127
+ # vision = gcloud.vision
128
+ #
129
+ # image = vision.image "path/to/face.jpg"
130
+ #
131
+ # face = image.face
132
+ #
133
+ # face.features.to_h.count #=> 9
134
+ # face.features.eyes.left.pupil
135
+ # #=> #<Landmark (x: 190.41544, y: 84.4557, z: -1.3682901)>
136
+ # face.features.chin.center
137
+ # #=> #<Landmark (x: 233.21977, y: 189.47475, z: 19.487228)>
138
+ # ```
139
+ #
140
+ # To run multiple features on an image in a single request, pass the image (or
141
+ # a string file path or Storage URI) to {Vision::Project#annotate}:
142
+ #
143
+ # ```ruby
144
+ # require "gcloud"
145
+ #
146
+ # gcloud = Gcloud.new
147
+ # vision = gcloud.vision
148
+ #
149
+ # image = vision.image "path/to/face.jpg"
150
+ #
151
+ # annotation = vision.annotate image, faces: true, labels: true
152
+ # annotation.faces.count #=> 1
153
+ # annotation.labels.count #=> 4
154
+ # ```
155
+ #
156
+ # You can also perform detection tasks on multiple images in a single request:
157
+ #
158
+ # ```ruby
159
+ # require "gcloud"
160
+ #
161
+ # gcloud = Gcloud.new
162
+ # vision = gcloud.vision
163
+ #
164
+ # face_image = vision.image "path/to/face.jpg"
165
+ # landmark_image = vision.image "path/to/landmark.jpg"
166
+ #
167
+ # annotations = vision.annotate face_image,
168
+ # landmark_image,
169
+ # faces: true,
170
+ # landmarks: true,
171
+ # labels: true
172
+ #
173
+ # annotations[0].faces.count #=> 1
174
+ # annotations[0].landmarks.count #=> 0
175
+ # annotations[0].labels.count #=> 4
176
+ # annotations[1].faces.count #=> 1
177
+ # annotations[1].landmarks.count #=> 1
178
+ # annotations[1].labels.count #=> 6
179
+ # ```
180
+ #
181
+ # It is even possible to configure different features for multiple images in
182
+ # a single call using a block. The following example results in a single
183
+ # request to the Cloud Vision API:
184
+ #
185
+ # ```ruby
186
+ # require "gcloud"
187
+ #
188
+ # gcloud = Gcloud.new
189
+ # vision = gcloud.vision
190
+ #
191
+ # face_image = vision.image "path/to/face.jpg"
192
+ # landmark_image = vision.image "path/to/landmark.jpg"
193
+ # text_image = vision.image "path/to/text.png"
194
+ #
195
+ # annotations = vision.annotate do |annotate|
196
+ # annotate.annotate face_image, faces: true, labels: true
197
+ # annotate.annotate landmark_image, landmarks: true
198
+ # annotate.annotate text_image, text: true
199
+ # end
200
+ #
201
+ # annotations[0].faces.count #=> 1
202
+ # annotations[0].labels.count #=> 4
203
+ # annotations[1].landmarks.count #=> 1
204
+ # annotations[2].text.words.count #=> 28
205
+ # ```
206
+ #
207
+ # The maximum number of results returned when performing face, landmark, logo,
208
+ # and label detection are defined by {Gcloud::Vision.default_max_faces},
209
+ # {Gcloud::Vision.default_max_landmarks}, {Gcloud::Vision.default_max_logos},
210
+ # and {Gcloud::Vision.default_max_labels}, respectively. To change the global
211
+ # defaults, you can update the configuration:
212
+ #
213
+ # ```ruby
214
+ # require "gcloud"
215
+ #
216
+ # gcloud = Gcloud.new
217
+ # vision = gcloud.vision
218
+ #
219
+ # Gcloud::Vision.default_max_faces = 1
220
+ #
221
+ # annotation = vision.annotate "path/to/face.jpg", faces: true
222
+ # annotation.faces.count #=> 1
223
+ # ```
224
+ #
225
+ # Or, to override a default for a single method call, simply pass an
226
+ # integer instead of a flag:
227
+ #
228
+ # ```ruby
229
+ # require "gcloud"
230
+ #
231
+ # gcloud = Gcloud.new
232
+ # vision = gcloud.vision
233
+ #
234
+ # image = vision.image "path/to/face.jpg"
235
+ #
236
+ # # Return just one face.
237
+ # annotation = vision.annotate image, faces: 1
238
+ # # Return up to 5 faces.
239
+ # annotation = vision.annotate image, faces: 5
240
+ # ```
241
+ #
242
+ module Vision
243
+ class << self
244
+ ##
245
+ # The default max results to return for facial detection requests. This is
246
+ # used on {Project#annotate} as well as {Image#faces}.
247
+ #
248
+ # The default value is `100`.
249
+ #
250
+ # @example Using the default setting on {Project#annotate}:
251
+ # require "gcloud"
252
+ #
253
+ # gcloud = Gcloud.new
254
+ # vision = gcloud.vision
255
+ #
256
+ # Gcloud::Vision.default_max_faces #=> 100
257
+ #
258
+ # annotation = vision.annotate "path/to/faces.jpg", faces: true
259
+ # # This is the same as calling
260
+ # # annotation = vision.annotate "path/to/faces.jpg", faces: 100
261
+ #
262
+ # @example Updating the default setting on {Project#annotate}:
263
+ # require "gcloud"
264
+ #
265
+ # gcloud = Gcloud.new
266
+ # vision = gcloud.vision
267
+ #
268
+ # # Set a new default
269
+ # Gcloud::Vision.default_max_faces = 5
270
+ #
271
+ # annotation = vision.annotate "path/to/faces.jpg", faces: true
272
+ # # This is the same as calling
273
+ # # annotation = vision.annotate "path/to/faces.jpg", faces: 5
274
+ #
275
+ #
276
+ # @example Using the default setting on {Image#faces}:
277
+ # require "gcloud"
278
+ #
279
+ # gcloud = Gcloud.new
280
+ # vision = gcloud.vision
281
+ #
282
+ # Gcloud::Vision.default_max_faces #=> 100
283
+ #
284
+ # faces = vision.image("path/to/faces.jpg").faces
285
+ # # This is the same as calling
286
+ # # faces = vision.image("path/to/faces.jpg").faces 100
287
+ #
288
+ # @example Updating the default setting on {Image#faces}:
289
+ # require "gcloud"
290
+ #
291
+ # gcloud = Gcloud.new
292
+ # vision = gcloud.vision
293
+ #
294
+ # # Set a new default
295
+ # Gcloud::Vision.default_max_faces = 5
296
+ #
297
+ # faces = vision.image("path/to/faces.jpg").faces
298
+ # # This is the same as calling
299
+ # # faces = vision.image("path/to/faces.jpg").faces 5
300
+ #
301
+ attr_accessor :default_max_faces
302
+
303
+ ##
304
+ # The default max results to return for landmark detection requests. This
305
+ # is used on {Project#annotate} as well as {Image#landmarks}.
306
+ #
307
+ # The default value is 100.
308
+ #
309
+ # @example Using the default setting on {Project#annotate}:
310
+ # require "gcloud"
311
+ #
312
+ # gcloud = Gcloud.new
313
+ # vision = gcloud.vision
314
+ #
315
+ # Gcloud::Vision.default_max_landmarks #=> 100
316
+ #
317
+ # annotation = vision.annotate "path/to/landmarks.jpg", landmarks: true
318
+ # # This is the same as calling
319
+ # # annotation = vision.annotate "path/to/landmarks.jpg", landmarks: 100
320
+ #
321
+ # @example Updating the default setting on {Project#annotate}:
322
+ # require "gcloud"
323
+ #
324
+ # gcloud = Gcloud.new
325
+ # vision = gcloud.vision
326
+ #
327
+ # # Set a new default
328
+ # Gcloud::Vision.default_max_landmarks = 5
329
+ #
330
+ # annotation = vision.annotate "path/to/landmarks.jpg", landmarks: true
331
+ # # This is the same as calling
332
+ # # annotation = vision.annotate "path/to/landmarks.jpg", landmarks: 5
333
+ #
334
+ #
335
+ # @example Using the default setting on {Image#landmarks}:
336
+ # require "gcloud"
337
+ #
338
+ # gcloud = Gcloud.new
339
+ # vision = gcloud.vision
340
+ #
341
+ # Gcloud::Vision.default_max_landmarks #=> 100
342
+ #
343
+ # landmarks = vision.image("path/to/landmarks.jpg").landmarks
344
+ # # This is the same as calling
345
+ # # landmarks = vision.image("path/to/landmarks.jpg").landmarks 100
346
+ #
347
+ # @example Updating the default setting on {Image#landmarks}:
348
+ # require "gcloud"
349
+ #
350
+ # gcloud = Gcloud.new
351
+ # vision = gcloud.vision
352
+ #
353
+ # # Set a new default
354
+ # Gcloud::Vision.default_max_landmarks = 5
355
+ #
356
+ # landmarks = vision.image("path/to/landmarks.jpg").landmarks
357
+ # # This is the same as calling
358
+ # # landmarks = vision.image("path/to/landmarks.jpg").landmarks 5
359
+ #
360
+ attr_accessor :default_max_landmarks
361
+
362
+ ##
363
+ # The default max results to return for logo detection requests. This is
364
+ # used on {Project#annotate} as well as {Image#logos}.
365
+ #
366
+ # The default value is 100.
367
+ #
368
+ # @example Using the default setting on {Project#annotate}:
369
+ # require "gcloud"
370
+ #
371
+ # gcloud = Gcloud.new
372
+ # vision = gcloud.vision
373
+ #
374
+ # Gcloud::Vision.default_max_logos #=> 100
375
+ #
376
+ # annotation = vision.annotate "path/to/logos.jpg", logos: true
377
+ # # This is the same as calling
378
+ # # annotation = vision.annotate "path/to/logos.jpg", logos: 100
379
+ #
380
+ # @example Updating the default setting on {Project#annotate}:
381
+ # require "gcloud"
382
+ #
383
+ # gcloud = Gcloud.new
384
+ # vision = gcloud.vision
385
+ #
386
+ # # Set a new default
387
+ # Gcloud::Vision.default_max_logos = 5
388
+ #
389
+ # annotation = vision.annotate "path/to/logos.jpg", logos: true
390
+ # # This is the same as calling
391
+ # # annotation = vision.annotate "path/to/logos.jpg", logos: 5
392
+ #
393
+ #
394
+ # @example Using the default setting on {Image#logos}:
395
+ # require "gcloud"
396
+ #
397
+ # gcloud = Gcloud.new
398
+ # vision = gcloud.vision
399
+ #
400
+ # Gcloud::Vision.default_max_logos #=> 100
401
+ #
402
+ # logos = vision.image("path/to/logos.jpg").logos
403
+ # # This is the same as calling
404
+ # # logos = vision.image("path/to/logos.jpg").logos 100
405
+ #
406
+ # @example Updating the default setting on {Image#logos}:
407
+ # require "gcloud"
408
+ #
409
+ # gcloud = Gcloud.new
410
+ # vision = gcloud.vision
411
+ #
412
+ # # Set a new default
413
+ # Gcloud::Vision.default_max_logos = 5
414
+ #
415
+ # logos = vision.image("path/to/logos.jpg").logos
416
+ # # This is the same as calling
417
+ # # logos = vision.image("path/to/logos.jpg").logos 5
418
+ #
419
+ attr_accessor :default_max_logos
420
+
421
+ ##
422
+ # The default max results to return for label detection requests. This is
423
+ # used on {Project#annotate} as well as {Image#labels}.
424
+ #
425
+ # The default value is 100.
426
+ #
427
+ # @example Using the default setting on {Project#annotate}:
428
+ # require "gcloud"
429
+ #
430
+ # gcloud = Gcloud.new
431
+ # vision = gcloud.vision
432
+ #
433
+ # Gcloud::Vision.default_max_labels #=> 100
434
+ #
435
+ # annotation = vision.annotate "path/to/labels.jpg", labels: true
436
+ # # This is the same as calling
437
+ # # annotation = vision.annotate "path/to/labels.jpg", labels: 100
438
+ #
439
+ # @example Updating the default setting on {Project#annotate}:
440
+ # require "gcloud"
441
+ #
442
+ # gcloud = Gcloud.new
443
+ # vision = gcloud.vision
444
+ #
445
+ # # Set a new default
446
+ # Gcloud::Vision.default_max_labels = 5
447
+ #
448
+ # annotation = vision.annotate "path/to/labels.jpg", labels: true
449
+ # # This is the same as calling
450
+ # # annotation = vision.annotate "path/to/labels.jpg", labels: 5
451
+ #
452
+ #
453
+ # @example Using the default setting on {Image#labels}:
454
+ # require "gcloud"
455
+ #
456
+ # gcloud = Gcloud.new
457
+ # vision = gcloud.vision
458
+ #
459
+ # Gcloud::Vision.default_max_labels #=> 100
460
+ #
461
+ # labels = vision.image("path/to/labels.jpg").labels
462
+ # # This is the same as calling
463
+ # # labels = vision.image("path/to/labels.jpg").labels 100
464
+ #
465
+ # @example Updating the default setting on {Image#labels}:
466
+ # require "gcloud"
467
+ #
468
+ # gcloud = Gcloud.new
469
+ # vision = gcloud.vision
470
+ #
471
+ # # Set a new default
472
+ # Gcloud::Vision.default_max_labels = 5
473
+ #
474
+ # labels = vision.image("path/to/labels.jpg").labels
475
+ # # This is the same as calling
476
+ # # labels = vision.image("path/to/labels.jpg").labels 5
477
+ #
478
+ attr_accessor :default_max_labels
479
+ end
480
+
481
+ # Set the default values.
482
+ # Update the comments documentation when these change.
483
+ self.default_max_faces = 100
484
+ self.default_max_landmarks = 100
485
+ self.default_max_logos = 100
486
+ self.default_max_labels = 100
487
+ end
488
+ end