google-cloud-video_intelligence-v1beta2 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,408 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # Auto-generated by gapic-generator-ruby. DO NOT EDIT!
18
+
19
+ require "google/cloud/errors"
20
+ require "google/cloud/videointelligence/v1beta2/video_intelligence_pb"
21
+
22
+ module Google
23
+ module Cloud
24
+ module VideoIntelligence
25
+ module V1beta2
26
+ module VideoIntelligenceService
27
+ ##
28
+ # Client for the VideoIntelligenceService service.
29
+ #
30
+ # Service that implements Google Cloud Video Intelligence API.
31
+ #
32
+ class Client
33
+ # @private
34
+ attr_reader :video_intelligence_service_stub
35
+
36
+ ##
37
+ # Configure the VideoIntelligenceService Client class.
38
+ #
39
+ # See {Google::Cloud::VideoIntelligence::V1beta2::VideoIntelligenceService::Client::Configuration}
40
+ # for a description of the configuration fields.
41
+ #
42
+ # ## Example
43
+ #
44
+ # To modify the configuration for all VideoIntelligenceService clients:
45
+ #
46
+ # Google::Cloud::VideoIntelligence::V1beta2::VideoIntelligenceService::Client.configure do |config|
47
+ # config.timeout = 10_000
48
+ # end
49
+ #
50
+ # @yield [config] Configure the Client client.
51
+ # @yieldparam config [Client::Configuration]
52
+ #
53
+ # @return [Client::Configuration]
54
+ #
55
+ def self.configure
56
+ @configure ||= begin
57
+ namespace = ["Google", "Cloud", "VideoIntelligence", "V1beta2"]
58
+ parent_config = while namespace.any?
59
+ parent_name = namespace.join "::"
60
+ parent_const = const_get parent_name
61
+ break parent_const.configure if parent_const&.respond_to? :configure
62
+ namespace.pop
63
+ end
64
+ default_config = Client::Configuration.new parent_config
65
+
66
+ default_config.rpcs.annotate_video.timeout = 600.0
67
+ default_config.rpcs.annotate_video.retry_policy = {
68
+ initial_delay: 1.0,
69
+ max_delay: 120.0,
70
+ multiplier: 2.5,
71
+ retry_codes: ["UNAVAILABLE", "DEADLINE_EXCEEDED"]
72
+ }
73
+
74
+ default_config
75
+ end
76
+ yield @configure if block_given?
77
+ @configure
78
+ end
79
+
80
+ ##
81
+ # Configure the VideoIntelligenceService Client instance.
82
+ #
83
+ # The configuration is set to the derived mode, meaning that values can be changed,
84
+ # but structural changes (adding new fields, etc.) are not allowed. Structural changes
85
+ # should be made on {Client.configure}.
86
+ #
87
+ # See {Google::Cloud::VideoIntelligence::V1beta2::VideoIntelligenceService::Client::Configuration}
88
+ # for a description of the configuration fields.
89
+ #
90
+ # @yield [config] Configure the Client client.
91
+ # @yieldparam config [Client::Configuration]
92
+ #
93
+ # @return [Client::Configuration]
94
+ #
95
+ def configure
96
+ yield @config if block_given?
97
+ @config
98
+ end
99
+
100
+ ##
101
+ # Create a new VideoIntelligenceService client object.
102
+ #
103
+ # ## Examples
104
+ #
105
+ # To create a new VideoIntelligenceService client with the default
106
+ # configuration:
107
+ #
108
+ # client = Google::Cloud::VideoIntelligence::V1beta2::VideoIntelligenceService::Client.new
109
+ #
110
+ # To create a new VideoIntelligenceService client with a custom
111
+ # configuration:
112
+ #
113
+ # client = Google::Cloud::VideoIntelligence::V1beta2::VideoIntelligenceService::Client.new do |config|
114
+ # config.timeout = 10_000
115
+ # end
116
+ #
117
+ # @yield [config] Configure the VideoIntelligenceService client.
118
+ # @yieldparam config [Client::Configuration]
119
+ #
120
+ def initialize
121
+ # These require statements are intentionally placed here to initialize
122
+ # the gRPC module only when it's required.
123
+ # See https://github.com/googleapis/toolkit/issues/446
124
+ require "gapic/grpc"
125
+ require "google/cloud/videointelligence/v1beta2/video_intelligence_services_pb"
126
+
127
+ # Create the configuration object
128
+ @config = Configuration.new Client.configure
129
+
130
+ # Yield the configuration if needed
131
+ yield @config if block_given?
132
+
133
+ # Create credentials
134
+ credentials = @config.credentials
135
+ credentials ||= Credentials.default scope: @config.scope
136
+ if credentials.is_a?(String) || credentials.is_a?(Hash)
137
+ credentials = Credentials.new credentials, scope: @config.scope
138
+ end
139
+ @quota_project_id = credentials.respond_to?(:quota_project_id) ? credentials.quota_project_id : nil
140
+
141
+ @operations_client = Operations.new do |config|
142
+ config.credentials = credentials
143
+ config.endpoint = @config.endpoint
144
+ end
145
+
146
+ @video_intelligence_service_stub = Gapic::ServiceStub.new(
147
+ Google::Cloud::VideoIntelligence::V1beta2::VideoIntelligenceService::Stub,
148
+ credentials: credentials,
149
+ endpoint: @config.endpoint,
150
+ channel_args: @config.channel_args,
151
+ interceptors: @config.interceptors
152
+ )
153
+ end
154
+
155
+ ##
156
+ # Get the associated client for long-running operations.
157
+ #
158
+ # @return [Google::Cloud::VideoIntelligence::V1beta2::VideoIntelligenceService::Operations]
159
+ #
160
+ attr_reader :operations_client
161
+
162
+ # Service calls
163
+
164
+ ##
165
+ # Performs asynchronous video annotation. Progress and results can be
166
+ # retrieved through the `google.longrunning.Operations` interface.
167
+ # `Operation.metadata` contains `AnnotateVideoProgress` (progress).
168
+ # `Operation.response` contains `AnnotateVideoResponse` (results).
169
+ #
170
+ # @overload annotate_video(request, options = nil)
171
+ # Pass arguments to `annotate_video` via a request object, either of type
172
+ # {Google::Cloud::VideoIntelligence::V1beta2::AnnotateVideoRequest} or an equivalent Hash.
173
+ #
174
+ # @param request [Google::Cloud::VideoIntelligence::V1beta2::AnnotateVideoRequest, Hash]
175
+ # A request object representing the call parameters. Required. To specify no
176
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
177
+ # @param options [Gapic::CallOptions, Hash]
178
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
179
+ #
180
+ # @overload annotate_video(input_uri: nil, input_content: nil, features: nil, video_context: nil, output_uri: nil, location_id: nil)
181
+ # Pass arguments to `annotate_video` via keyword arguments. Note that at
182
+ # least one keyword argument is required. To specify no parameters, or to keep all
183
+ # the default parameter values, pass an empty Hash as a request object (see above).
184
+ #
185
+ # @param input_uri [String]
186
+ # Input video location. Currently, only
187
+ # [Google Cloud Storage](https://cloud.google.com/storage/) URIs are
188
+ # supported, which must be specified in the following format:
189
+ # `gs://bucket-id/object-id` (other URI formats return
190
+ # [google.rpc.Code.INVALID_ARGUMENT][google.rpc.Code.INVALID_ARGUMENT]). For
191
+ # more information, see [Request URIs](https://cloud.google.com/storage/docs/request-endpoints). A video
192
+ # URI may include wildcards in `object-id`, and thus identify multiple
193
+ # videos. Supported wildcards: '*' to match 0 or more characters;
194
+ # '?' to match 1 character. If unset, the input video should be embedded
195
+ # in the request as `input_content`. If set, `input_content` should be unset.
196
+ # @param input_content [String]
197
+ # The video data bytes.
198
+ # If unset, the input video(s) should be specified via `input_uri`.
199
+ # If set, `input_uri` should be unset.
200
+ # @param features [Array<Google::Cloud::VideoIntelligence::V1beta2::Feature>]
201
+ # Required. Requested video annotation features.
202
+ # @param video_context [Google::Cloud::VideoIntelligence::V1beta2::VideoContext, Hash]
203
+ # Additional video context and/or feature-specific parameters.
204
+ # @param output_uri [String]
205
+ # Optional. Location where the output (in JSON format) should be stored.
206
+ # Currently, only [Google Cloud Storage](https://cloud.google.com/storage/)
207
+ # URIs are supported, which must be specified in the following format:
208
+ # `gs://bucket-id/object-id` (other URI formats return
209
+ # [google.rpc.Code.INVALID_ARGUMENT][google.rpc.Code.INVALID_ARGUMENT]). For
210
+ # more information, see [Request URIs](https://cloud.google.com/storage/docs/request-endpoints).
211
+ # @param location_id [String]
212
+ # Optional. Cloud region where annotation should take place. Supported cloud
213
+ # regions: `us-east1`, `us-west1`, `europe-west1`, `asia-east1`. If no region
214
+ # is specified, a region will be determined based on video file location.
215
+ #
216
+ # @yield [response, operation] Access the result along with the RPC operation
217
+ # @yieldparam response [Gapic::Operation]
218
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
219
+ #
220
+ # @return [Gapic::Operation]
221
+ #
222
+ # @raise [Google::Cloud::Error] if the RPC is aborted.
223
+ #
224
+ def annotate_video request, options = nil
225
+ raise ArgumentError, "request must be provided" if request.nil?
226
+
227
+ request = Gapic::Protobuf.coerce request, to: Google::Cloud::VideoIntelligence::V1beta2::AnnotateVideoRequest
228
+
229
+ # Converts hash and nil to an options object
230
+ options = Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
231
+
232
+ # Customize the options with defaults
233
+ metadata = @config.rpcs.annotate_video.metadata.to_h
234
+
235
+ # Set x-goog-api-client and x-goog-user-project headers
236
+ metadata[:"x-goog-api-client"] ||= Gapic::Headers.x_goog_api_client \
237
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
238
+ gapic_version: ::Google::Cloud::VideoIntelligence::V1beta2::VERSION
239
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
240
+
241
+ options.apply_defaults timeout: @config.rpcs.annotate_video.timeout,
242
+ metadata: metadata,
243
+ retry_policy: @config.rpcs.annotate_video.retry_policy
244
+ options.apply_defaults metadata: @config.metadata,
245
+ retry_policy: @config.retry_policy
246
+
247
+ @video_intelligence_service_stub.call_rpc :annotate_video, request, options: options do |response, operation|
248
+ response = Gapic::Operation.new response, @operations_client, options: options
249
+ yield response, operation if block_given?
250
+ return response
251
+ end
252
+ rescue GRPC::BadStatus => e
253
+ raise Google::Cloud::Error.from_error(e)
254
+ end
255
+
256
+ ##
257
+ # Configuration class for the VideoIntelligenceService API.
258
+ #
259
+ # This class represents the configuration for VideoIntelligenceService,
260
+ # providing control over timeouts, retry behavior, logging, transport
261
+ # parameters, and other low-level controls. Certain parameters can also be
262
+ # applied individually to specific RPCs. See
263
+ # {Google::Cloud::VideoIntelligence::V1beta2::VideoIntelligenceService::Client::Configuration::Rpcs}
264
+ # for a list of RPCs that can be configured independently.
265
+ #
266
+ # Configuration can be applied globally to all clients, or to a single client
267
+ # on construction.
268
+ #
269
+ # # Examples
270
+ #
271
+ # To modify the global config, setting the timeout for annotate_video
272
+ # to 20 seconds, and all remaining timeouts to 10 seconds:
273
+ #
274
+ # Google::Cloud::VideoIntelligence::V1beta2::VideoIntelligenceService::Client.configure do |config|
275
+ # config.timeout = 10_000
276
+ # config.rpcs.annotate_video.timeout = 20_000
277
+ # end
278
+ #
279
+ # To apply the above configuration only to a new client:
280
+ #
281
+ # client = Google::Cloud::VideoIntelligence::V1beta2::VideoIntelligenceService::Client.new do |config|
282
+ # config.timeout = 10_000
283
+ # config.rpcs.annotate_video.timeout = 20_000
284
+ # end
285
+ #
286
+ # @!attribute [rw] endpoint
287
+ # The hostname or hostname:port of the service endpoint.
288
+ # Defaults to `"videointelligence.googleapis.com"`.
289
+ # @return [String]
290
+ # @!attribute [rw] credentials
291
+ # Credentials to send with calls. You may provide any of the following types:
292
+ # * (`String`) The path to a service account key file in JSON format
293
+ # * (`Hash`) A service account key as a Hash
294
+ # * (`Google::Auth::Credentials`) A googleauth credentials object
295
+ # (see the [googleauth docs](https://googleapis.dev/ruby/googleauth/latest/index.html))
296
+ # * (`Signet::OAuth2::Client`) A signet oauth2 client object
297
+ # (see the [signet docs](https://googleapis.dev/ruby/signet/latest/Signet/OAuth2/Client.html))
298
+ # * (`GRPC::Core::Channel`) a gRPC channel with included credentials
299
+ # * (`GRPC::Core::ChannelCredentials`) a gRPC credentails object
300
+ # * (`nil`) indicating no credentials
301
+ # @return [Object]
302
+ # @!attribute [rw] scope
303
+ # The OAuth scopes
304
+ # @return [Array<String>]
305
+ # @!attribute [rw] lib_name
306
+ # The library name as recorded in instrumentation and logging
307
+ # @return [String]
308
+ # @!attribute [rw] lib_version
309
+ # The library version as recorded in instrumentation and logging
310
+ # @return [String]
311
+ # @!attribute [rw] channel_args
312
+ # Extra parameters passed to the gRPC channel. Note: this is ignored if a
313
+ # `GRPC::Core::Channel` object is provided as the credential.
314
+ # @return [Hash]
315
+ # @!attribute [rw] interceptors
316
+ # An array of interceptors that are run before calls are executed.
317
+ # @return [Array<GRPC::ClientInterceptor>]
318
+ # @!attribute [rw] timeout
319
+ # The call timeout in milliseconds.
320
+ # @return [Numeric]
321
+ # @!attribute [rw] metadata
322
+ # Additional gRPC headers to be sent with the call.
323
+ # @return [Hash{Symbol=>String}]
324
+ # @!attribute [rw] retry_policy
325
+ # The retry policy. The value is a hash with the following keys:
326
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
327
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
328
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
329
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
330
+ # trigger a retry.
331
+ # @return [Hash]
332
+ #
333
+ class Configuration
334
+ extend Gapic::Config
335
+
336
+ config_attr :endpoint, "videointelligence.googleapis.com", String
337
+ config_attr :credentials, nil do |value|
338
+ allowed = [::String, ::Hash, ::Proc, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
339
+ allowed += [::GRPC::Core::Channel, ::GRPC::Core::ChannelCredentials] if defined? ::GRPC
340
+ allowed.any? { |klass| klass === value }
341
+ end
342
+ config_attr :scope, nil, String, Array, nil
343
+ config_attr :lib_name, nil, String, nil
344
+ config_attr :lib_version, nil, String, nil
345
+ config_attr(:channel_args, { "grpc.service_config_disable_resolution"=>1 }, Hash, nil)
346
+ config_attr :interceptors, nil, Array, nil
347
+ config_attr :timeout, nil, Numeric, nil
348
+ config_attr :metadata, nil, Hash, nil
349
+ config_attr :retry_policy, nil, Hash, Proc, nil
350
+
351
+ # @private
352
+ def initialize parent_config = nil
353
+ @parent_config = parent_config unless parent_config.nil?
354
+
355
+ yield self if block_given?
356
+ end
357
+
358
+ ##
359
+ # Configurations for individual RPCs
360
+ # @return [Rpcs]
361
+ #
362
+ def rpcs
363
+ @rpcs ||= begin
364
+ parent_rpcs = nil
365
+ parent_rpcs = @parent_config.rpcs if @parent_config&.respond_to? :rpcs
366
+ Rpcs.new parent_rpcs
367
+ end
368
+ end
369
+
370
+ ##
371
+ # Configuration RPC class for the VideoIntelligenceService API.
372
+ #
373
+ # Includes fields providing the configuration for each RPC in this service.
374
+ # Each configuration object is of type `Gapic::Config::Method` and includes
375
+ # the following configuration fields:
376
+ #
377
+ # * `timeout` (*type:* `Numeric`) - The call timeout in milliseconds
378
+ # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional gRPC headers
379
+ # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
380
+ # include the following keys:
381
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
382
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
383
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
384
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
385
+ # trigger a retry.
386
+ #
387
+ class Rpcs
388
+ ##
389
+ # RPC-specific configuration for `annotate_video`
390
+ # @return [Gapic::Config::Method]
391
+ #
392
+ attr_reader :annotate_video
393
+
394
+ # @private
395
+ def initialize parent_rpcs = nil
396
+ annotate_video_config = parent_rpcs&.annotate_video if parent_rpcs&.respond_to? :annotate_video
397
+ @annotate_video = Gapic::Config::Method.new annotate_video_config
398
+
399
+ yield self if block_given?
400
+ end
401
+ end
402
+ end
403
+ end
404
+ end
405
+ end
406
+ end
407
+ end
408
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # Auto-generated by gapic-generator-ruby. DO NOT EDIT!
18
+
19
+ require "googleauth"
20
+
21
+ module Google
22
+ module Cloud
23
+ module VideoIntelligence
24
+ module V1beta2
25
+ module VideoIntelligenceService
26
+ # Credentials for the VideoIntelligenceService API.
27
+ class Credentials < Google::Auth::Credentials
28
+ self.scope = [
29
+ "https://www.googleapis.com/auth/cloud-platform"
30
+ ]
31
+ self.env_vars = [
32
+ "VIDEO_INTELLIGENCE_CREDENTIALS",
33
+ "VIDEO_INTELLIGENCE_KEYFILE",
34
+ "GOOGLE_CLOUD_CREDENTIALS",
35
+ "GOOGLE_CLOUD_KEYFILE",
36
+ "GCLOUD_KEYFILE",
37
+ "VIDEO_INTELLIGENCE_CREDENTIALS_JSON",
38
+ "VIDEO_INTELLIGENCE_KEYFILE_JSON",
39
+ "GOOGLE_CLOUD_CREDENTIALS_JSON",
40
+ "GOOGLE_CLOUD_KEYFILE_JSON",
41
+ "GCLOUD_KEYFILE_JSON"
42
+ ]
43
+ self.paths = [
44
+ "~/.config/google_cloud/application_default_credentials.json"
45
+ ]
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end