Migrating to google-cloud-video_intelligence 3.0
The 3.0 release of the google-cloud-video_intelligence client is a significant upgradebased on anext-gen code generator,and includes substantial interface changes. Existing code written for earlierversions of this library will likely require updates to use this version.This document describes the changes that have been made, and what you need todo to update your usage.
To summarize:
- The library has been broken out into multiple libraries. The new gems
google-cloud-video_intelligence-v1,google-cloud-video_intelligence-v1beta2,google-cloud-video_intelligence-v1p1beta1, andgoogle-cloud-video_intelligence-v1p2beta1contain theactual client classes for the various versions of the VideoIntelligence service,and the gemgoogle-cloud-video_intelligencenow simply provides a convenience wrapper.SeeLibrary Structure for more info. - The library uses a new configuration mechanism giving you closer controlover endpoint address, network timeouts, and retry. SeeClient Configuration for more info. Furthermore,when creating a client object, you can customize its configuration in ablock rather than passing arguments to the constructor. SeeCreating Clients for more info.
- Previously, positional arguments were used to indicate required arguments.Now, all method arguments are keyword arguments, with documentation thatspecifies whether they are required or optional. Additionally, you can passa proto request object instead of separate arguments. SeePassing Arguments for more info.
- Previously, clients reported RPC errors by raising instances of
Google::Gax::GaxErrorand its subclasses. Now, RPC exceptions are of typeGoogle::Cloud::Errorand its subclasses. SeeHandling Errors for more info. - Some classes have moved into different namespaces. SeeClass Namespaces for more info.
Library Structure
Older releases of thegoogle-cloud-video_intelligence gem were all-in-one gemsthat included potentially multiple clients for multiple versions of the Video Intelligenceservice. TheGoogle::Cloud::VideoIntelligence.new factory method wouldreturn you an instance of aGoogle::Cloud::VideoIntelligence::V1::VideoIntelligenceServiceClientobject for the V1 version of the service, (or other corresponding classes forother versions of the service). All these classes were defined in the same gem.
With the 3.0 release, thegoogle-cloud-video_intelligence gem still provides factorymethods for obtaining clients. (The method signatures will have changed. SeeCreating Clients for details.) However, the actual clientclasses have been moved into separate gems, one per service version. TheGoogle::Cloud::VideoIntelligence::V1::VideoIntelligenceService::Client class, along with itshelpers and data types, is now part of thegoogle-cloud-video_intelligence-v1 gem.Corresponding classes for other versions of the service are similarly moved toother gems with the version in the gem name.
For normal usage, you can continue to install thegoogle-cloud-video_intelligence gem(which will bring in the versioned client gems as dependencies) and continue touse factory methods to create clients. However, you may alternatively choose toinstall only one of the versioned gems. For example, if you know you will onlyuseV1 of the service, you can installgoogle-cloud-video_intelligence-v1 byitself, and construct instances of theGoogle::Cloud::VideoIntelligence::V1::VideoIntelligenceService::Client client class directly.
Client Configuration
In older releases, if you wanted to customize performance parameters orlow-level behavior of the client (such as credentials, timeouts, orinstrumentation), you would pass a variety of keyword arguments to the clientconstructor. It was also extremely difficult to customize the default settings.
With the 3.0 release, a configuration interface provides control over theseparameters, including defaults for all instances of a client, and settings foreach specific client instance. For example, to set default credentials andtimeout for all Speech V1 clients:
Google::Cloud::VideoIntelligence::V1::VideoIntelligenceService::Client.configure do |config| config.credentials = "/path/to/credentials.json" config.timeout = 10.0endIndividual RPCs can also be configured independently. For example, to set thetimeout for theannotate_video call:
Google::Cloud::VideoIntelligence::V1::VideoIntelligenceService::Client.configure do |config| config.rpcs.annotate_video.timeout = 20.0endDefaults for certain configurations can be set for all Video Intelligence versions andservices globally:
Google::Cloud::VideoIntelligence.configure do |config| config.credentials = "/path/to/credentials.json" config.timeout = 10.0endFinally, you can override the configuration for each client instance. See thenext section onCreating Clients for details.
Creating Clients
In older releases, to create a client object, you would use theGoogle::Cloud::VideoIntelligence.new class method. Keyword arguments were available toselect a service version and to configure parameters such as credentials andtimeouts.
With the 3.0 release, use theGoogle::Cloud::VideoIntelligence.video_intelligence_service classmethod to create a client object. You may select a service version using the:version keyword argument. However, other configuration parameters should beset in a configuration block when you create the client.
Old:
client = Google::Cloud::VideoIntelligence.new credentials: "/path/to/credentials.json"New:
client = Google::Cloud::VideoIntelligence.video_intelligence_service do |config| config.credentials = "/path/to/credentials.json"endThe configuration block is optional. If you do not provide it, or you do notset some configuration parameters, then the default configuration is used. SeeClient Configuration.
Passing Arguments
In older releases, required arguments would be passed as positional methodarguments, while most optional arguments would be passed as keyword arguments.
With the 3.0 release, all RPC arguments are passed as keyword arguments,regardless of whether they are required or optional. For example:
Old:
client = Google::Cloud::VideoIntelligence.newfeatures = [Google::Cloud::VideoIntelligence::V1::Feature::FACE_DETECTION]input_uri = "gs://my-bucket/my-video"# features is a positional argument, but input_uri is a keyword argumentresponse = client.annotate_video features, input_uri: input_uriNew:
client = Google::Cloud::VideoIntelligence.video_intelligence_servicefeatures = [Google::Cloud::VideoIntelligence::V1::Feature::FACE_DETECTION]input_uri = "gs://my-bucket/my-video"# features and input_uri are both keyword argumentsresponse = client.annotate_video features: features, input_uri: input_uriIn the 3.0 release, it is also possible to pass a request object, eitheras a hash or as a protocol buffer.
New:
client = Google::Cloud::VideoIntelligence.video_intelligence_servicerequest = Google::Cloud::VideoIntelligence::V1::AnnotateVideoRequest.new( features: [Google::Cloud::VideoIntelligence::V1::Feature::FACE_DETECTION], input_uri: "gs://my-bucket/my-video")# Pass a request object as a positional argument:response = client.annotate_video requestFinally, in older releases, to provide call options, you would pass aGoogle::Gax::CallOptions object with the:options keyword argument. In the3.0 release, pass call options using asecond set of keyword arguments.
Old:
client = Google::Cloud::VideoIntelligence.newfeatures = [Google::Cloud::VideoIntelligence::V1::Feature::FACE_DETECTION]input_uri = "gs://my-bucket/my-video"options = Google::Gax::CallOptions.new timeout: 10.0response = client.annotate_video features, input_uri: input_uri, options: optionsNew:
client = Google::Cloud::VideoIntelligence.video_intelligence_servicefeatures = [Google::Cloud::VideoIntelligence::V1::Feature::FACE_DETECTION]input_uri = "gs://my-bucket/my-video"# Use a hash to wrap the normal call arguments (or pass a request object), and# then add further keyword arguments for the call options.response = client.annotate_video( { features: features, input_uri: input_uri }, timeout: 10.0)Handling Errors
The client reports standardgRPC error codesby raising exceptions. In older releases, these exceptions were located in theGoogle::Gax namespace and were subclasses of theGoogle::Gax::GaxError baseexception class, defined in thegoogle-gax gem. However, these classes weredifferent from the standard exceptions (subclasses ofGoogle::Cloud::Error)thrown by other client libraries such asgoogle-cloud-storage.
The 3.0 client library now uses theGoogle::Cloud::Error exception hierarchy,for consistency across all the Google Cloud client libraries. In general, theseexceptions have the same name as their counterparts from older releases, butare located in theGoogle::Cloud namespace rather than theGoogle::Gaxnamespace.
Old:
client = Google::Cloud::VideoIntelligence.newfeatures = [Google::Cloud::VideoIntelligence::V1::Feature::FACE_DETECTION]input_uri = "gs://my-bucket/my-video"begin response = client.annotate_video features, input_uri: input_urirescue Google::Gax::Error => e # Handle exceptions that subclass Google::Gax::ErrorendNew:
client = Google::Cloud::VideoIntelligence.video_intelligence_servicefeatures = [Google::Cloud::VideoIntelligence::V1::Feature::FACE_DETECTION]input_uri = "gs://my-bucket/my-video"begin response = client.annotate_video features: features, input_uri: input_urirescue Google::Cloud::Error => e # Handle exceptions that subclass Google::Cloud::ErrorendClass Namespaces
In some significantly older releases, (protobuf) data type classes were locatedin the namespaceGoogle::Cloud::Videointelligence::V1 (note the lower-case "i".)In more recent releases, these were moved intoGoogle::Cloud::VideoIntelligence::V1(with an upper-case "I"), but the older namespace also continued to work.In the 3.0 release, the old namespace with a lower-case "i" has been dropped.
In older releases, the client object was of classes with names like:Google::Cloud::VideoIntelligence::V1::VideoIntelligenceServiceClient.In the 3.0 release, the client object is of a different class:Google::Cloud::VideoIntelligence::V1::VideoIntelligenceService::Client.Note that most users will use the factory methods such asGoogle::Cloud::VideoIntelligence.video_intelligence_service to create instances of the client object,so you may not need to reference the actual class directly.SeeCreating Clients.
In older releases, the credentials object was of classGoogle::Cloud::VideoIntelligence::V1::Credentials.In the 3.0 release, each service has its own credentials class, e.g.Google::Cloud::VideoIntelligence::V1::VideoIntelligenceService::Credentials.Again, most users will not need to reference this class directly.SeeClient Configuration.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-10-30 UTC.