google-cloud-video_intelligence 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,114 @@
1
+ # Copyright 2017, 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
+ module Google
16
+ module Protobuf
17
+ # +Any+ contains an arbitrary serialized protocol buffer message along with a
18
+ # URL that describes the type of the serialized message.
19
+ #
20
+ # Protobuf library provides support to pack/unpack Any values in the form
21
+ # of utility functions or additional generated methods of the Any type.
22
+ #
23
+ # Example 1: Pack and unpack a message in C++.
24
+ #
25
+ # Foo foo = ...;
26
+ # Any any;
27
+ # any.PackFrom(foo);
28
+ # ...
29
+ # if (any.UnpackTo(&foo)) {
30
+ # ...
31
+ # }
32
+ #
33
+ # Example 2: Pack and unpack a message in Java.
34
+ #
35
+ # Foo foo = ...;
36
+ # Any any = Any.pack(foo);
37
+ # ...
38
+ # if (any.is(Foo.class)) {
39
+ # foo = any.unpack(Foo.class);
40
+ # }
41
+ #
42
+ # Example 3: Pack and unpack a message in Python.
43
+ #
44
+ # foo = Foo(...)
45
+ # any = Any()
46
+ # any.Pack(foo)
47
+ # ...
48
+ # if any.Is(Foo.DESCRIPTOR):
49
+ # any.Unpack(foo)
50
+ # ...
51
+ #
52
+ # The pack methods provided by protobuf library will by default use
53
+ # 'type.googleapis.com/full.type.name' as the type URL and the unpack
54
+ # methods only use the fully qualified type name after the last '/'
55
+ # in the type URL, for example "foo.bar.com/x/y.z" will yield type
56
+ # name "y.z".
57
+ #
58
+ #
59
+ # = JSON
60
+ #
61
+ # The JSON representation of an +Any+ value uses the regular
62
+ # representation of the deserialized, embedded message, with an
63
+ # additional field +@type+ which contains the type URL. Example:
64
+ #
65
+ # package google.profile;
66
+ # message Person {
67
+ # string first_name = 1;
68
+ # string last_name = 2;
69
+ # }
70
+ #
71
+ # {
72
+ # "@type": "type.googleapis.com/google.profile.Person",
73
+ # "firstName": <string>,
74
+ # "lastName": <string>
75
+ # }
76
+ #
77
+ # If the embedded message type is well-known and has a custom JSON
78
+ # representation, that representation will be embedded adding a field
79
+ # +value+ which holds the custom JSON in addition to the +@type+
80
+ # field. Example (for message Google::Protobuf::Duration):
81
+ #
82
+ # {
83
+ # "@type": "type.googleapis.com/google.protobuf.Duration",
84
+ # "value": "1.212s"
85
+ # }
86
+ # @!attribute [rw] type_url
87
+ # @return [String]
88
+ # A URL/resource name whose content describes the type of the
89
+ # serialized protocol buffer message.
90
+ #
91
+ # For URLs which use the scheme +http+, +https+, or no scheme, the
92
+ # following restrictions and interpretations apply:
93
+ #
94
+ # * If no scheme is provided, +https+ is assumed.
95
+ # * The last segment of the URL's path must represent the fully
96
+ # qualified name of the type (as in +path/google.protobuf.Duration+).
97
+ # The name should be in a canonical form (e.g., leading "." is
98
+ # not accepted).
99
+ # * An HTTP GET on the URL must yield a Google::Protobuf::Type
100
+ # value in binary format, or produce an error.
101
+ # * Applications are allowed to cache lookup results based on the
102
+ # URL, or have them precompiled into a binary to avoid any
103
+ # lookup. Therefore, binary compatibility needs to be preserved
104
+ # on changes to types. (Use versioned type names to manage
105
+ # breaking changes.)
106
+ #
107
+ # Schemes other than +http+, +https+ (or the empty scheme) might be
108
+ # used with implementation specific semantics.
109
+ # @!attribute [rw] value
110
+ # @return [String]
111
+ # Must be a valid serialized protocol buffer of the above specified type.
112
+ class Any; end
113
+ end
114
+ end
@@ -0,0 +1,83 @@
1
+ # Copyright 2017, 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
+ module Google
16
+ module Rpc
17
+ # The +Status+ type defines a logical error model that is suitable for different
18
+ # programming environments, including REST APIs and RPC APIs. It is used by
19
+ # {gRPC}[https://github.com/grpc]. The error model is designed to be:
20
+ #
21
+ # * Simple to use and understand for most users
22
+ # * Flexible enough to meet unexpected needs
23
+ #
24
+ # = Overview
25
+ #
26
+ # The +Status+ message contains three pieces of data: error code, error message,
27
+ # and error details. The error code should be an enum value of
28
+ # Google::Rpc::Code, but it may accept additional error codes if needed. The
29
+ # error message should be a developer-facing English message that helps
30
+ # developers *understand* and *resolve* the error. If a localized user-facing
31
+ # error message is needed, put the localized message in the error details or
32
+ # localize it in the client. The optional error details may contain arbitrary
33
+ # information about the error. There is a predefined set of error detail types
34
+ # in the package +google.rpc+ which can be used for common error conditions.
35
+ #
36
+ # = Language mapping
37
+ #
38
+ # The +Status+ message is the logical representation of the error model, but it
39
+ # is not necessarily the actual wire format. When the +Status+ message is
40
+ # exposed in different client libraries and different wire protocols, it can be
41
+ # mapped differently. For example, it will likely be mapped to some exceptions
42
+ # in Java, but more likely mapped to some error codes in C.
43
+ #
44
+ # = Other uses
45
+ #
46
+ # The error model and the +Status+ message can be used in a variety of
47
+ # environments, either with or without APIs, to provide a
48
+ # consistent developer experience across different environments.
49
+ #
50
+ # Example uses of this error model include:
51
+ #
52
+ # * Partial errors. If a service needs to return partial errors to the client,
53
+ # it may embed the +Status+ in the normal response to indicate the partial
54
+ # errors.
55
+ #
56
+ # * Workflow errors. A typical workflow has multiple steps. Each step may
57
+ # have a +Status+ message for error reporting purpose.
58
+ #
59
+ # * Batch operations. If a client uses batch request and batch response, the
60
+ # +Status+ message should be used directly inside batch response, one for
61
+ # each error sub-response.
62
+ #
63
+ # * Asynchronous operations. If an API call embeds asynchronous operation
64
+ # results in its response, the status of those operations should be
65
+ # represented directly using the +Status+ message.
66
+ #
67
+ # * Logging. If some API errors are stored in logs, the message +Status+ could
68
+ # be used directly after any stripping needed for security/privacy reasons.
69
+ # @!attribute [rw] code
70
+ # @return [Integer]
71
+ # The status code, which should be an enum value of Google::Rpc::Code.
72
+ # @!attribute [rw] message
73
+ # @return [String]
74
+ # A developer-facing error message, which should be in English. Any
75
+ # user-facing error message should be localized and sent in the
76
+ # Google::Rpc::Status#details field, or localized by the client.
77
+ # @!attribute [rw] details
78
+ # @return [Array<Google::Protobuf::Any>]
79
+ # A list of messages that carry the error details. There will be a
80
+ # common set of message types for APIs to use.
81
+ class Status; end
82
+ end
83
+ end
@@ -0,0 +1,260 @@
1
+ # Copyright 2017, 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
+ # EDITING INSTRUCTIONS
16
+ # This file was generated from the file
17
+ # https://github.com/googleapis/googleapis/blob/master/google/cloud/videointelligence/v1beta1/video_intelligence.proto,
18
+ # and updates to that file get reflected here through a refresh process.
19
+ # For the short term, the refresh process will only be runnable by Google
20
+ # engineers.
21
+ #
22
+ # The only allowed edits are to method and file documentation. A 3-way
23
+ # merge preserves those additions if the generated source changes.
24
+
25
+ require "json"
26
+ require "pathname"
27
+
28
+ require "google/gax"
29
+ require "google/gax/operation"
30
+ require "google/longrunning/operations_client"
31
+
32
+ require "google/cloud/videointelligence/v1beta1/video_intelligence_pb"
33
+
34
+ module Google
35
+ module Cloud
36
+ module VideoIntelligence
37
+ module V1beta1
38
+ # Service that implements Google Cloud Video Intelligence API.
39
+ #
40
+ # @!attribute [r] video_intelligence_service_stub
41
+ # @return [Google::Cloud::Videointelligence::V1beta1::VideoIntelligenceService::Stub]
42
+ class VideoIntelligenceServiceClient
43
+ attr_reader :video_intelligence_service_stub
44
+
45
+ # The default address of the service.
46
+ SERVICE_ADDRESS = "videointelligence.googleapis.com".freeze
47
+
48
+ # The default port of the service.
49
+ DEFAULT_SERVICE_PORT = 443
50
+
51
+ DEFAULT_TIMEOUT = 30
52
+
53
+ # The scopes needed to make gRPC calls to all of the methods defined in
54
+ # this service.
55
+ ALL_SCOPES = [
56
+ "https://www.googleapis.com/auth/cloud-platform"
57
+ ].freeze
58
+
59
+ # @param service_path [String]
60
+ # The domain name of the API remote host.
61
+ # @param port [Integer]
62
+ # The port on which to connect to the remote host.
63
+ # @param channel [Channel]
64
+ # A Channel object through which to make calls.
65
+ # @param chan_creds [Grpc::ChannelCredentials]
66
+ # A ChannelCredentials for the setting up the RPC client.
67
+ # @param updater_proc [Proc]
68
+ # A function that transforms the metadata for requests, e.g., to give
69
+ # OAuth credentials.
70
+ # @param scopes [Array<String>]
71
+ # The OAuth scopes for this service. This parameter is ignored if
72
+ # an updater_proc is supplied.
73
+ # @param client_config[Hash]
74
+ # A Hash for call options for each method. See
75
+ # Google::Gax#construct_settings for the structure of
76
+ # this data. Falls back to the default config if not specified
77
+ # or the specified config is missing data points.
78
+ # @param timeout [Numeric]
79
+ # The default timeout, in seconds, for calls made through this client.
80
+ def initialize \
81
+ service_path: SERVICE_ADDRESS,
82
+ port: DEFAULT_SERVICE_PORT,
83
+ channel: nil,
84
+ chan_creds: nil,
85
+ updater_proc: nil,
86
+ scopes: ALL_SCOPES,
87
+ client_config: {},
88
+ timeout: DEFAULT_TIMEOUT,
89
+ app_name: nil,
90
+ app_version: nil,
91
+ lib_name: nil,
92
+ lib_version: ""
93
+ # These require statements are intentionally placed here to initialize
94
+ # the gRPC module only when it's required.
95
+ # See https://github.com/googleapis/toolkit/issues/446
96
+ require "google/gax/grpc"
97
+ require "google/cloud/videointelligence/v1beta1/video_intelligence_services_pb"
98
+
99
+ @operations_client = Google::Longrunning::OperationsClient.new(
100
+ service_path: service_path,
101
+ port: port,
102
+ channel: channel,
103
+ chan_creds: chan_creds,
104
+ updater_proc: updater_proc,
105
+ scopes: scopes,
106
+ client_config: client_config,
107
+ timeout: timeout,
108
+ app_name: app_name,
109
+ app_version: app_version,
110
+ lib_name: lib_name,
111
+ lib_version: lib_version,
112
+ )
113
+
114
+ if app_name || app_version
115
+ warn "`app_name` and `app_version` are no longer being used in the request headers."
116
+ end
117
+
118
+ google_api_client = "gl-ruby/#{RUBY_VERSION}"
119
+ google_api_client << " #{lib_name}/#{lib_version}" if lib_name
120
+ google_api_client << " gapic/0.6.8 gax/#{Google::Gax::VERSION}"
121
+ google_api_client << " grpc/#{GRPC::VERSION}"
122
+ google_api_client.freeze
123
+
124
+ headers = { :"x-goog-api-client" => google_api_client }
125
+ client_config_file = Pathname.new(__dir__).join(
126
+ "video_intelligence_service_client_config.json"
127
+ )
128
+ defaults = client_config_file.open do |f|
129
+ Google::Gax.construct_settings(
130
+ "google.cloud.videointelligence.v1beta1.VideoIntelligenceService",
131
+ JSON.parse(f.read),
132
+ client_config,
133
+ Google::Gax::Grpc::STATUS_CODE_NAMES,
134
+ timeout,
135
+ errors: Google::Gax::Grpc::API_ERRORS,
136
+ kwargs: headers
137
+ )
138
+ end
139
+ @video_intelligence_service_stub = Google::Gax::Grpc.create_stub(
140
+ service_path,
141
+ port,
142
+ chan_creds: chan_creds,
143
+ channel: channel,
144
+ updater_proc: updater_proc,
145
+ scopes: scopes,
146
+ &Google::Cloud::Videointelligence::V1beta1::VideoIntelligenceService::Stub.method(:new)
147
+ )
148
+
149
+ @annotate_video = Google::Gax.create_api_call(
150
+ @video_intelligence_service_stub.method(:annotate_video),
151
+ defaults["annotate_video"]
152
+ )
153
+ end
154
+
155
+ # Service calls
156
+
157
+ # Performs asynchronous video annotation. Progress and results can be
158
+ # retrieved through the +google.longrunning.Operations+ interface.
159
+ # +Operation.metadata+ contains +AnnotateVideoProgress+ (progress).
160
+ # +Operation.response+ contains +AnnotateVideoResponse+ (results).
161
+ #
162
+ # @param input_uri [String]
163
+ # Input video location. Currently, only
164
+ # {Google Cloud Storage}[https://cloud.google.com/storage/] URIs are
165
+ # supported, which must be specified in the following format:
166
+ # +gs://bucket-id/object-id+ (other URI formats return
167
+ # Google::Rpc::Code::INVALID_ARGUMENT). For more information, see
168
+ # {Request URIs}[https://cloud.google.com/storage/docs/reference-uris].
169
+ # A video URI may include wildcards in +object-id+, and thus identify
170
+ # multiple videos. Supported wildcards: '*' to match 0 or more characters;
171
+ # '?' to match 1 character. If unset, the input video should be embedded
172
+ # in the request as +input_content+. If set, +input_content+ should be unset.
173
+ # @param features [Array<Google::Cloud::Videointelligence::V1beta1::Feature>]
174
+ # Requested video annotation features.
175
+ # @param input_content [String]
176
+ # The video data bytes. Encoding: base64. If unset, the input video(s)
177
+ # should be specified via +input_uri+. If set, +input_uri+ should be unset.
178
+ # @param video_context [Google::Cloud::Videointelligence::V1beta1::VideoContext]
179
+ # Additional video context and/or feature-specific parameters.
180
+ # @param output_uri [String]
181
+ # Optional location where the output (in JSON format) should be stored.
182
+ # Currently, only {Google Cloud Storage}[https://cloud.google.com/storage/]
183
+ # URIs are supported, which must be specified in the following format:
184
+ # +gs://bucket-id/object-id+ (other URI formats return
185
+ # Google::Rpc::Code::INVALID_ARGUMENT). For more information, see
186
+ # {Request URIs}[https://cloud.google.com/storage/docs/reference-uris].
187
+ # @param location_id [String]
188
+ # Optional cloud region where annotation should take place. Supported cloud
189
+ # regions: +us-east1+, +us-west1+, +europe-west1+, +asia-east1+. If no region
190
+ # is specified, a region will be determined based on video file location.
191
+ # @param options [Google::Gax::CallOptions]
192
+ # Overrides the default settings for this call, e.g, timeout,
193
+ # retries, etc.
194
+ # @return [Google::Gax::Operation]
195
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
196
+ # @example
197
+ # require "google/cloud/video_intelligence/v1beta1"
198
+ #
199
+ # video_intelligence_service_client = Google::Cloud::VideoIntelligence::V1beta1::VideoIntelligenceServiceClient.new
200
+ # input_uri = ''
201
+ # features = []
202
+ #
203
+ # # Register a callback during the method call.
204
+ # operation = video_intelligence_service_client.annotate_video(input_uri, features) do |op|
205
+ # raise op.results.message if op.error?
206
+ # op_results = op.results
207
+ # # Process the results.
208
+ #
209
+ # metadata = op.metadata
210
+ # # Process the metadata.
211
+ # end
212
+ #
213
+ # # Or use the return value to register a callback.
214
+ # operation.on_done do |op|
215
+ # raise op.results.message if op.error?
216
+ # op_results = op.results
217
+ # # Process the results.
218
+ #
219
+ # metadata = op.metadata
220
+ # # Process the metadata.
221
+ # end
222
+ #
223
+ # # Manually reload the operation.
224
+ # operation.reload!
225
+ #
226
+ # # Or block until the operation completes, triggering callbacks on
227
+ # # completion.
228
+ # operation.wait_until_done!
229
+
230
+ def annotate_video \
231
+ input_uri,
232
+ features,
233
+ input_content: nil,
234
+ video_context: nil,
235
+ output_uri: nil,
236
+ location_id: nil,
237
+ options: nil
238
+ req = Google::Cloud::Videointelligence::V1beta1::AnnotateVideoRequest.new({
239
+ input_uri: input_uri,
240
+ features: features,
241
+ input_content: input_content,
242
+ video_context: video_context,
243
+ output_uri: output_uri,
244
+ location_id: location_id
245
+ }.delete_if { |_, v| v.nil? })
246
+ operation = Google::Gax::Operation.new(
247
+ @annotate_video.call(req, options),
248
+ @operations_client,
249
+ Google::Cloud::Videointelligence::V1beta1::AnnotateVideoResponse,
250
+ Google::Cloud::Videointelligence::V1beta1::AnnotateVideoProgress,
251
+ call_options: options
252
+ )
253
+ operation.on_done { |operation| yield(operation) } if block_given?
254
+ operation
255
+ end
256
+ end
257
+ end
258
+ end
259
+ end
260
+ end