gcloud 0.12.2 → 0.20.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 (169) hide show
  1. checksums.yaml +5 -13
  2. data/lib/gcloud.rb +27 -456
  3. data/lib/gcloud/bigquery.rb +2 -382
  4. data/lib/gcloud/datastore.rb +2 -576
  5. data/lib/gcloud/dns.rb +2 -321
  6. data/lib/gcloud/logging.rb +1 -322
  7. data/lib/gcloud/pubsub.rb +2 -476
  8. data/lib/gcloud/resource_manager.rb +2 -273
  9. data/lib/gcloud/storage.rb +2 -440
  10. data/lib/gcloud/translate.rb +1 -250
  11. data/lib/gcloud/version.rb +2 -2
  12. data/lib/gcloud/vision.rb +1 -501
  13. metadata +36 -332
  14. data/AUTHENTICATION.md +0 -75
  15. data/CHANGELOG.md +0 -382
  16. data/OVERVIEW.md +0 -259
  17. data/lib/gcloud/backoff.rb +0 -150
  18. data/lib/gcloud/bigquery/copy_job.rb +0 -97
  19. data/lib/gcloud/bigquery/credentials.rb +0 -29
  20. data/lib/gcloud/bigquery/data.rb +0 -239
  21. data/lib/gcloud/bigquery/dataset.rb +0 -753
  22. data/lib/gcloud/bigquery/dataset/access.rb +0 -507
  23. data/lib/gcloud/bigquery/dataset/list.rb +0 -169
  24. data/lib/gcloud/bigquery/extract_job.rb +0 -117
  25. data/lib/gcloud/bigquery/insert_response.rb +0 -81
  26. data/lib/gcloud/bigquery/job.rb +0 -299
  27. data/lib/gcloud/bigquery/job/list.rb +0 -172
  28. data/lib/gcloud/bigquery/load_job.rb +0 -202
  29. data/lib/gcloud/bigquery/project.rb +0 -475
  30. data/lib/gcloud/bigquery/query_data.rb +0 -234
  31. data/lib/gcloud/bigquery/query_job.rb +0 -137
  32. data/lib/gcloud/bigquery/schema.rb +0 -359
  33. data/lib/gcloud/bigquery/service.rb +0 -506
  34. data/lib/gcloud/bigquery/table.rb +0 -1141
  35. data/lib/gcloud/bigquery/table/list.rb +0 -180
  36. data/lib/gcloud/bigquery/view.rb +0 -475
  37. data/lib/gcloud/credentials.rb +0 -129
  38. data/lib/gcloud/datastore/commit.rb +0 -148
  39. data/lib/gcloud/datastore/credentials.rb +0 -35
  40. data/lib/gcloud/datastore/cursor.rb +0 -76
  41. data/lib/gcloud/datastore/dataset.rb +0 -660
  42. data/lib/gcloud/datastore/dataset/lookup_results.rb +0 -219
  43. data/lib/gcloud/datastore/dataset/query_results.rb +0 -386
  44. data/lib/gcloud/datastore/entity.rb +0 -449
  45. data/lib/gcloud/datastore/errors.rb +0 -41
  46. data/lib/gcloud/datastore/gql_query.rb +0 -211
  47. data/lib/gcloud/datastore/grpc_utils.rb +0 -132
  48. data/lib/gcloud/datastore/key.rb +0 -281
  49. data/lib/gcloud/datastore/properties.rb +0 -128
  50. data/lib/gcloud/datastore/query.rb +0 -348
  51. data/lib/gcloud/datastore/service.rb +0 -167
  52. data/lib/gcloud/datastore/transaction.rb +0 -362
  53. data/lib/gcloud/dns/change.rb +0 -158
  54. data/lib/gcloud/dns/change/list.rb +0 -173
  55. data/lib/gcloud/dns/credentials.rb +0 -29
  56. data/lib/gcloud/dns/importer.rb +0 -183
  57. data/lib/gcloud/dns/project.rb +0 -247
  58. data/lib/gcloud/dns/record.rb +0 -170
  59. data/lib/gcloud/dns/record/list.rb +0 -174
  60. data/lib/gcloud/dns/service.rb +0 -167
  61. data/lib/gcloud/dns/zone.rb +0 -759
  62. data/lib/gcloud/dns/zone/list.rb +0 -168
  63. data/lib/gcloud/dns/zone/transaction.rb +0 -176
  64. data/lib/gcloud/errors.rb +0 -206
  65. data/lib/gcloud/gce.rb +0 -56
  66. data/lib/gcloud/grpc_utils.rb +0 -87
  67. data/lib/gcloud/logging/credentials.rb +0 -29
  68. data/lib/gcloud/logging/entry.rb +0 -465
  69. data/lib/gcloud/logging/entry/http_request.rb +0 -141
  70. data/lib/gcloud/logging/entry/list.rb +0 -177
  71. data/lib/gcloud/logging/entry/operation.rb +0 -90
  72. data/lib/gcloud/logging/logger.rb +0 -307
  73. data/lib/gcloud/logging/metric.rb +0 -169
  74. data/lib/gcloud/logging/metric/list.rb +0 -172
  75. data/lib/gcloud/logging/project.rb +0 -642
  76. data/lib/gcloud/logging/resource.rb +0 -84
  77. data/lib/gcloud/logging/resource_descriptor.rb +0 -137
  78. data/lib/gcloud/logging/resource_descriptor/list.rb +0 -174
  79. data/lib/gcloud/logging/service.rb +0 -267
  80. data/lib/gcloud/logging/sink.rb +0 -227
  81. data/lib/gcloud/logging/sink/list.rb +0 -171
  82. data/lib/gcloud/pubsub/credentials.rb +0 -29
  83. data/lib/gcloud/pubsub/message.rb +0 -94
  84. data/lib/gcloud/pubsub/policy.rb +0 -204
  85. data/lib/gcloud/pubsub/project.rb +0 -482
  86. data/lib/gcloud/pubsub/received_message.rb +0 -160
  87. data/lib/gcloud/pubsub/service.rb +0 -334
  88. data/lib/gcloud/pubsub/subscription.rb +0 -565
  89. data/lib/gcloud/pubsub/subscription/list.rb +0 -208
  90. data/lib/gcloud/pubsub/topic.rb +0 -511
  91. data/lib/gcloud/pubsub/topic/list.rb +0 -174
  92. data/lib/gcloud/pubsub/topic/publisher.rb +0 -85
  93. data/lib/gcloud/resource_manager/credentials.rb +0 -30
  94. data/lib/gcloud/resource_manager/manager.rb +0 -266
  95. data/lib/gcloud/resource_manager/policy.rb +0 -211
  96. data/lib/gcloud/resource_manager/project.rb +0 -484
  97. data/lib/gcloud/resource_manager/project/list.rb +0 -167
  98. data/lib/gcloud/resource_manager/project/updater.rb +0 -130
  99. data/lib/gcloud/resource_manager/service.rb +0 -127
  100. data/lib/gcloud/storage/bucket.rb +0 -775
  101. data/lib/gcloud/storage/bucket/acl.rb +0 -810
  102. data/lib/gcloud/storage/bucket/cors.rb +0 -153
  103. data/lib/gcloud/storage/bucket/list.rb +0 -172
  104. data/lib/gcloud/storage/credentials.rb +0 -29
  105. data/lib/gcloud/storage/errors.rb +0 -65
  106. data/lib/gcloud/storage/file.rb +0 -842
  107. data/lib/gcloud/storage/file/acl.rb +0 -425
  108. data/lib/gcloud/storage/file/list.rb +0 -191
  109. data/lib/gcloud/storage/file/verifier.rb +0 -67
  110. data/lib/gcloud/storage/project.rb +0 -316
  111. data/lib/gcloud/storage/service.rb +0 -347
  112. data/lib/gcloud/translate/api.rb +0 -241
  113. data/lib/gcloud/translate/detection.rb +0 -137
  114. data/lib/gcloud/translate/language.rb +0 -69
  115. data/lib/gcloud/translate/service.rb +0 -80
  116. data/lib/gcloud/translate/translation.rb +0 -112
  117. data/lib/gcloud/vision/annotate.rb +0 -224
  118. data/lib/gcloud/vision/annotation.rb +0 -455
  119. data/lib/gcloud/vision/annotation/entity.rb +0 -234
  120. data/lib/gcloud/vision/annotation/face.rb +0 -1750
  121. data/lib/gcloud/vision/annotation/properties.rb +0 -245
  122. data/lib/gcloud/vision/annotation/safe_search.rb +0 -161
  123. data/lib/gcloud/vision/annotation/text.rb +0 -236
  124. data/lib/gcloud/vision/annotation/vertex.rb +0 -108
  125. data/lib/gcloud/vision/credentials.rb +0 -29
  126. data/lib/gcloud/vision/image.rb +0 -590
  127. data/lib/gcloud/vision/location.rb +0 -115
  128. data/lib/gcloud/vision/project.rb +0 -278
  129. data/lib/gcloud/vision/service.rb +0 -66
  130. data/lib/google/api/annotations.rb +0 -14
  131. data/lib/google/api/http.rb +0 -30
  132. data/lib/google/api/label.rb +0 -24
  133. data/lib/google/api/monitored_resource.rb +0 -25
  134. data/lib/google/datastore/v1beta3/datastore.rb +0 -115
  135. data/lib/google/datastore/v1beta3/datastore_services.rb +0 -33
  136. data/lib/google/datastore/v1beta3/entity.rb +0 -63
  137. data/lib/google/datastore/v1beta3/query.rb +0 -128
  138. data/lib/google/devtools/cloudtrace/v1/trace.rb +0 -78
  139. data/lib/google/devtools/cloudtrace/v1/trace_services.rb +0 -32
  140. data/lib/google/example/library/v1/library.rb +0 -91
  141. data/lib/google/example/library/v1/library_services.rb +0 -40
  142. data/lib/google/iam/v1/iam_policy.rb +0 -33
  143. data/lib/google/iam/v1/iam_policy_services.rb +0 -30
  144. data/lib/google/iam/v1/policy.rb +0 -25
  145. data/lib/google/logging/type/http_request.rb +0 -28
  146. data/lib/google/logging/type/log_severity.rb +0 -27
  147. data/lib/google/logging/v2/log_entry.rb +0 -44
  148. data/lib/google/logging/v2/logging.rb +0 -56
  149. data/lib/google/logging/v2/logging_config.rb +0 -59
  150. data/lib/google/logging/v2/logging_config_services.rb +0 -32
  151. data/lib/google/logging/v2/logging_metrics.rb +0 -51
  152. data/lib/google/logging/v2/logging_metrics_services.rb +0 -32
  153. data/lib/google/logging/v2/logging_services.rb +0 -31
  154. data/lib/google/longrunning/operations.rb +0 -50
  155. data/lib/google/longrunning/operations_services.rb +0 -29
  156. data/lib/google/protobuf/descriptor.rb +0 -0
  157. data/lib/google/pubsub/v1/pubsub.rb +0 -129
  158. data/lib/google/pubsub/v1/pubsub_services.rb +0 -56
  159. data/lib/google/pubsub/v1beta2/pubsub.rb +0 -126
  160. data/lib/google/pubsub/v1beta2/pubsub_services.rb +0 -56
  161. data/lib/google/rpc/code.rb +0 -32
  162. data/lib/google/rpc/error_details.rb +0 -61
  163. data/lib/google/rpc/status.rb +0 -19
  164. data/lib/google/type/color.rb +0 -20
  165. data/lib/google/type/date.rb +0 -18
  166. data/lib/google/type/dayofweek.rb +0 -23
  167. data/lib/google/type/latlng.rb +0 -17
  168. data/lib/google/type/money.rb +0 -18
  169. data/lib/google/type/timeofday.rb +0 -19
@@ -1,115 +0,0 @@
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
- module Gcloud
17
- module Vision
18
- ##
19
- # # Location
20
- #
21
- # A latitude/longitude pair with values conforming to the [WGS84
22
- # standard](http://www.unoosa.org/pdf/icg/2012/template/WGS_84.pdf).
23
- #
24
- # @attr [Float] latitude The degrees latitude conforming to the [WGS84
25
- # standard](http://www.unoosa.org/pdf/icg/2012/template/WGS_84.pdf).
26
- # @attr [Float] longitude The degrees longitude conforming to the [WGS84
27
- # standard](http://www.unoosa.org/pdf/icg/2012/template/WGS_84.pdf).
28
- #
29
- # @example
30
- # require "gcloud"
31
- #
32
- # gcloud = Gcloud.new
33
- # vision = gcloud.vision
34
- #
35
- # image = vision.image "path/to/landmark.jpg"
36
- # entity = image.landmark
37
- #
38
- # location = entity.locations.first
39
- #
40
- # location.latitude #=> 43.878264
41
- # location.longitude #=> -103.45700740814209
42
- #
43
- class Location
44
- attr_accessor :latitude, :longitude
45
-
46
- ##
47
- # @private Creates a new Location instance.
48
- def initialize latitude, longitude
49
- @latitude = latitude
50
- @longitude = longitude
51
- end
52
-
53
- ##
54
- # Returns the object's property values as an array.
55
- #
56
- # @return [Array]
57
- #
58
- def to_a
59
- to_ary
60
- end
61
-
62
- ##
63
- # Returns the object's property values as an array.
64
- #
65
- # @return [Array]
66
- #
67
- def to_ary
68
- [latitude, longitude]
69
- end
70
-
71
- ##
72
- # Converts object to a hash. All keys will be symbolized.
73
- #
74
- # @return [Hash]
75
- #
76
- def to_h
77
- to_hash
78
- end
79
-
80
- ##
81
- # Converts object to a hash. All keys will be symbolized.
82
- #
83
- # @return [Hash]
84
- #
85
- def to_hash
86
- { latitude: latitude, longitude: longitude }
87
- end
88
-
89
- # @private
90
- def to_s
91
- "(latitude: #{latitude.inspect}, longitude: #{longitude.inspect})"
92
- end
93
-
94
- # @private
95
- def inspect
96
- "#<#{self.class.name} #{self}>"
97
- end
98
-
99
- ##
100
- # @private New Google API Client LatLng object.
101
- def to_gapi
102
- Google::Apis::VisionV1::LatLng.new(
103
- latitude: latitude,
104
- longitude: longitude
105
- )
106
- end
107
-
108
- ##
109
- # @private New Location from a Google API Client LatLng object.
110
- def self.from_gapi gapi
111
- new gapi.latitude, gapi.longitude
112
- end
113
- end
114
- end
115
- end
@@ -1,278 +0,0 @@
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/gce"
17
- require "gcloud/errors"
18
- require "gcloud/vision/service"
19
- require "gcloud/vision/credentials"
20
- require "gcloud/vision/annotate"
21
- require "gcloud/vision/image"
22
- require "gcloud/vision/annotation"
23
-
24
- module Gcloud
25
- module Vision
26
- ##
27
- # # Project
28
- #
29
- # Google Cloud Vision allows easy integration of vision detection features
30
- # within developer applications, including image labeling, face and landmark
31
- # detection, optical character recognition (OCR), and tagging of explicit
32
- # content.
33
- #
34
- # @example
35
- # require "gcloud"
36
- #
37
- # gcloud = Gcloud.new
38
- # vision = gcloud.vision
39
- #
40
- # image = vision.image "path/to/landmark.jpg"
41
- #
42
- # annotation = vision.annotate image, labels: true
43
- #
44
- # annotation.labels.map &:description
45
- # #=> ["stone carving", "ancient history", "statue", "sculpture",
46
- # #=> "monument", "landmark"]
47
- #
48
- # See Gcloud#vision
49
- class Project
50
- ##
51
- # @private The Service object.
52
- attr_accessor :service
53
-
54
- ##
55
- # @private Creates a new Project instance.
56
- def initialize service
57
- @service = service
58
- end
59
-
60
- # The Vision project connected to.
61
- #
62
- # @example
63
- # require "gcloud"
64
- #
65
- # gcloud = Gcloud.new "my-todo-project",
66
- # "/path/to/keyfile.json"
67
- # vision = gcloud.vision
68
- #
69
- # vision.project #=> "my-todo-project"
70
- #
71
- def project
72
- service.project
73
- end
74
-
75
- ##
76
- # @private Default project.
77
- def self.default_project
78
- ENV["VISION_PROJECT"] ||
79
- ENV["GCLOUD_PROJECT"] ||
80
- ENV["GOOGLE_CLOUD_PROJECT"] ||
81
- Gcloud::GCE.project_id
82
- end
83
-
84
- ##
85
- # Returns a new image from the given source.
86
- #
87
- # Cloud Vision sets upper limits on file size as well as on the total
88
- # combined size of all images in a request. Reducing your file size can
89
- # significantly improve throughput; however, be careful not to reduce
90
- # image quality in the process. See [Best Practices - Image
91
- # Sizing](https://cloud.google.com/vision/docs/image-best-practices#image_sizing)
92
- # for current file size limits.
93
- #
94
- # Note that an object in Google Cloud Storage is a single entity;
95
- # permissions affect only that object. "Directory permissions" do not
96
- # exist (though default bucket permissions do exist). Make sure the code
97
- # which performs your request has access to that image.
98
- #
99
- # @see https://cloud.google.com/vision/docs/image-best-practices Best
100
- # Practices
101
- #
102
- # @param [String, IO, StringIO, Tempfile, Gcloud::Storage::File] source A
103
- # string file path or Cloud Storage URI of the form
104
- # `"gs://bucketname/path/to/image_filename"`; or a File, IO, StringIO,
105
- # or Tempfile instance; or an instance of Gcloud::Storage::File.
106
- #
107
- # @return [Image] An image for the Vision service.
108
- #
109
- # @example With a Google Cloud Storage URI:
110
- # require "gcloud"
111
- #
112
- # gcloud = Gcloud.new
113
- # vision = gcloud.vision
114
- #
115
- # image = vision.image "gs://bucket-name/path_to_image_object"
116
- #
117
- # @example With a local file path:
118
- # require "gcloud"
119
- #
120
- # gcloud = Gcloud.new
121
- # vision = gcloud.vision
122
- #
123
- # image = vision.image "path/to/landmark.jpg"
124
- #
125
- def image source
126
- return source if source.is_a? Image
127
- Image.from_source source, self
128
- end
129
-
130
- ##
131
- # Performs detection of Cloud Vision [features](https://cloud.google.com/vision/reference/rest/v1/images/annotate#Feature)
132
- # on the given image(s). If no options for features are provided, **all**
133
- # image detection features will be performed, with a default of `100`
134
- # results for faces, landmarks, logos, and labels. If any feature option
135
- # is provided, only the specified feature detections will be performed.
136
- # Please review [Pricing](https://cloud.google.com/vision/docs/pricing)
137
- # before use, as a separate charge is incurred for each feature performed
138
- # on an image.
139
- #
140
- # Cloud Vision sets upper limits on file size as well as on the total
141
- # combined size of all images in a request. Reducing your file size can
142
- # significantly improve throughput; however, be careful not to reduce
143
- # image quality in the process. See [Best Practices - Image
144
- # Sizing](https://cloud.google.com/vision/docs/image-best-practices#image_sizing)
145
- # for current file size limits.
146
- #
147
- # @see https://cloud.google.com/vision/docs/requests-and-responses Cloud
148
- # Vision API Requests and Responses
149
- # @see https://cloud.google.com/vision/reference/rest/v1/images/annotate#AnnotateImageRequest
150
- # AnnotateImageRequest
151
- # @see https://cloud.google.com/vision/docs/pricing Cloud Vision Pricing
152
- #
153
- # @param [Image, Object] images The image or images to annotate. This can
154
- # be an {Image} instance, or any other type that converts to an {Image}.
155
- # See {#image} for details.
156
- # @param [Boolean, Integer] faces Whether to perform the facial detection
157
- # feature. The maximum number of results is configured in
158
- # {Gcloud::Vision.default_max_faces}, or may be provided here. Optional.
159
- # @param [Boolean, Integer] landmarks Whether to perform the landmark
160
- # detection feature. The maximum number of results is configured in
161
- # {Gcloud::Vision.default_max_landmarks}, or may be provided here.
162
- # Optional.
163
- # @param [Boolean, Integer] logos Whether to perform the logo detection
164
- # feature. The maximum number of results is configured in
165
- # {Gcloud::Vision.default_max_logos}, or may be provided here. Optional.
166
- # @param [Boolean, Integer] labels Whether to perform the label detection
167
- # feature. The maximum number of results is configured in
168
- # {Gcloud::Vision.default_max_labels}, or may be provided here.
169
- # Optional.
170
- # @param [Boolean] text Whether to perform the text (OCR) feature.
171
- # Optional.
172
- # @param [Boolean] safe_search Whether to perform the safe search feature.
173
- # Optional.
174
- # @param [Boolean] properties Whether to perform the image properties
175
- # feature (currently, the image's dominant colors.) Optional.
176
- #
177
- # @yield [annotate] A block for requests that involve multiple feature
178
- # configurations. See {Annotate#annotate}.
179
- # @yieldparam [Annotate] annotate the Annotate object
180
- #
181
- # @return [Annotation, Array<Annotation>] The results for all image
182
- # detections, returned as a single {Annotation} instance for one image,
183
- # or as an array of {Annotation} instances, one per image, for multiple
184
- # images.
185
- #
186
- # @example With a single image:
187
- # require "gcloud"
188
- #
189
- # gcloud = Gcloud.new
190
- # vision = gcloud.vision
191
- #
192
- # image = vision.image "path/to/landmark.jpg"
193
- #
194
- # annotation = vision.annotate image, labels: true
195
- #
196
- # annotation.labels.map &:description
197
- # #=> ["stone carving", "ancient history", "statue", "sculpture",
198
- # #=> "monument", "landmark"]
199
- #
200
- # @example With multiple images:
201
- # require "gcloud"
202
- #
203
- # gcloud = Gcloud.new
204
- # vision = gcloud.vision
205
- #
206
- # face_image = vision.image "path/to/face.jpg"
207
- # landmark_image = vision.image "path/to/landmark.jpg"
208
- #
209
- # annotations = vision.annotate face_image, landmark_image, labels: true
210
- #
211
- # annotations[0].labels.count #=> 4
212
- # annotations[1].labels.count #=> 6
213
- #
214
- # @example With multiple images and configurations passed in a block:
215
- # require "gcloud"
216
- #
217
- # gcloud = Gcloud.new
218
- # vision = gcloud.vision
219
- #
220
- # face_image = vision.image "path/to/face.jpg"
221
- # landmark_image = vision.image "path/to/landmark.jpg"
222
- # text_image = vision.image "path/to/text.png"
223
- #
224
- # annotations = vision.annotate do |annotate|
225
- # annotate.annotate face_image, faces: true, labels: true
226
- # annotate.annotate landmark_image, landmarks: true
227
- # annotate.annotate text_image, text: true
228
- # end
229
- #
230
- # annotations[0].faces.count #=> 1
231
- # annotations[0].labels.count #=> 4
232
- # annotations[1].landmarks.count #=> 1
233
- # annotations[2].text.words.count #=> 28
234
- #
235
- # @example Maximum result values can also be provided:
236
- # require "gcloud"
237
- #
238
- # gcloud = Gcloud.new
239
- # vision = gcloud.vision
240
- #
241
- # image = vision.image "path/to/landmark.jpg"
242
- #
243
- # annotation = vision.annotate image, labels: 3
244
- #
245
- # annotation.labels.map &:description
246
- # #=> ["stone carving", "ancient history", "statue"]
247
- #
248
- def annotate *images, faces: false, landmarks: false, logos: false,
249
- labels: false, text: false, safe_search: false,
250
- properties: false
251
- a = Annotate.new self
252
- a.annotate(*images, faces: faces, landmarks: landmarks, logos: logos,
253
- labels: labels, text: text,
254
- safe_search: safe_search, properties: properties)
255
-
256
- yield a if block_given?
257
-
258
- gapi = service.annotate a.requests
259
- annotations = Array(gapi.responses).map do |g|
260
- fail Error.from_error(g.error) if g.error
261
- Annotation.from_gapi g
262
- end
263
- return annotations.first if annotations.count == 1
264
- annotations
265
- end
266
- alias_method :mark, :annotate
267
- alias_method :detect, :annotate
268
-
269
- protected
270
-
271
- ##
272
- # Raise an error unless an active connection is available.
273
- def ensure_service!
274
- fail "Must have active connection" unless service
275
- end
276
- end
277
- end
278
- end
@@ -1,66 +0,0 @@
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/vision_v1"
19
-
20
- module Gcloud
21
- module Vision
22
- ##
23
- # @private
24
- # Represents the service to Vision, exposing the API calls.
25
- class Service
26
- ##
27
- # Alias to the Google Client API module
28
- API = Google::Apis::VisionV1
29
-
30
- attr_accessor :project
31
- attr_accessor :credentials
32
-
33
- ##
34
- # Creates a new Service instance.
35
- def initialize project, credentials, retries: nil, timeout: nil
36
- @project = project
37
- @credentials = credentials
38
- @service = API::VisionService.new
39
- @service.client_options.application_name = "gcloud-ruby"
40
- @service.client_options.application_version = Gcloud::VERSION
41
- @service.request_options.retries = retries || 3
42
- @service.request_options.timeout_sec = timeout if timeout
43
- @service.authorization = @credentials.client
44
- end
45
-
46
- def service
47
- return mocked_service if mocked_service
48
- @service
49
- end
50
- attr_accessor :mocked_service
51
-
52
- ##
53
- # Returns API::BatchAnnotateImagesResponse
54
- def annotate requests
55
- request = API::BatchAnnotateImagesRequest.new(requests: requests)
56
- service.annotate_image request
57
- rescue Google::Apis::Error => e
58
- raise Gcloud::Error.from_error(e)
59
- end
60
-
61
- def inspect
62
- "#{self.class}(#{@project})"
63
- end
64
- end
65
- end
66
- end