Skip to content

Commit

Permalink
docs(language): fix a few errors in the language migration guide
Browse files Browse the repository at this point in the history
  • Loading branch information
dazuma authored Mar 19, 2020
1 parent 5ce7f7c commit 5c289b6
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 36 deletions.
66 changes: 42 additions & 24 deletions google-cloud-language/MIGRATING.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
## Migrating to google-cloud-language 1.0

The 1.0 release of the google-cloud-language client is a significant upgrade
based on a next-gen code generator. If you have used earlier versions of this
library, there have been a number of significant changes that may require
updates to calling code. This document will describe the changes that have been
made, and what you need to do to update your usage.
based on a [next-gen code generator](https://github.com/googleapis/gapic-generator-ruby),
and includes substantial interface changes. Existing code written for earlier
versions of this library will likely require updates to use this version.
This document describes the changes that have been made, and what you need to
do to update your usage.

To summarize:

Expand All @@ -14,15 +15,16 @@ To summarize:
service, and the gem `google-cloud-language` now simply provides a
convenience wrapper. See [Library Structure](#library-structure) for more
info.
* This library uses a new configuration mechanism giving you closer control
* The library uses a new configuration mechanism giving you closer control
over endpoint address, network timeouts, and retry. See
[Client Configuration](#client-configuration) for more info. Furthermore,
when creating a client object, you can customize its configuration in a
block rather than passing arguments to the constructor. See
[Creating Clients](#creating-clients) for more info.
* Previously, methods typically had at least one positional argument. Now,
all arguments are keyword arguments. Additionally, you can pass a proto
request object instead of separate arguments. See
* Previously, positional arguments were used to indicate required arguments.
Now, all method arguments are keyword arguments, with documentation that
specifies whether they are required or optional. Additionally, you can pass
a proto request object instead of separate arguments. See
[Passing Arguments](#passing-arguments) for more info.
* Some classes have moved into different namespaces. See
[Class Namespaces](#class-namespaces) for more info.
Expand All @@ -31,7 +33,7 @@ To summarize:

Older 0.x releases of the `google-cloud-language` gem were all-in-one gems that
included potentially multiple clients for multiple versions of the Natural
Language service. The `Google::Cloud::Language.new()` factory method would
Language service. The `Google::Cloud::Language.new` factory method would
return you an instance of a `Google::Cloud::Language::V1::LanguageServiceClient`
object for the V1 version of the service, or a
`Google::Cloud::Language::V1beta2::LanguageServiceClient` object for the
Expand All @@ -40,18 +42,18 @@ V1beta2 version of the service. All these classes were defined in the same gem.
With the 1.0 release, the `google-cloud-language` gem still provides factory
methods for obtaining clients. (The method signatures will have changed. See
[Creating Clients](#creating-clients) for details.) However, the actual client
classes have been moved into separate gems, on per service version. The
classes have been moved into separate gems, one per service version. The
`Google::Cloud::Language::V1::LanguageService::Client` class, along with its
helpers and data types, are now part of the `google-cloud-language-v1` gem.
helpers and data types, is now part of the `google-cloud-language-v1` gem.
Similarly, the `Google::Cloud::Language::V1beta2::LanguageService::Client`
class is part of the `google-cloud-language-v1beta2` gem.

For normal usage, you can continue to install the `google-cloud-language` gem
and continue to use factory methods to create clients. This will remain the
easiest way to use the Natural Language client. However, you may alternatively
choose to install only one of the versioned gems. For example, if you know you
will only use `V1` of the service, you can install `google-cloud-language-v1`
by itself, and construct instances of the
(which will bring in the versioned client gems as dependencies) and continue to
use factory methods to create clients. However, you may alternatively choose to
install only one of the versioned gems. For example, if you know you will only
`V1` of the service, you can install `google-cloud-language-v1` by itself, and
construct instances of the
`Google::Cloud::Language::V1::LanguageService::Client` client class directly.

### Client Configuration
Expand All @@ -61,9 +63,10 @@ low-level behavior of the client (such as credentials, timeouts, or
instrumentation), you would pass a variety of keyword arguments to the client
constructor. It was also extremely difficult to customize the default settings.

With the 1.0 release, a configuration interface provides access to these
parameters, both global defaults and per-client settings. For example, to set
global credentials and default timeout for all language V1 clients:
With the 1.0 release, a configuration interface provides control over these
parameters, including defaults for all instances of a client, and settings for
each specific client instance. For example, to set default credentials and
timeout for all Language V1 clients:

```
Google::Cloud::Language::V1::LanguageService::Client.configure do |config|
Expand All @@ -81,14 +84,27 @@ Google::Cloud::Language::V1::LanguageService::Client.configure do |config|
end
```

Defaults for certain configurations can be set for all Language versions
globally:

```
Google::Cloud::Language.configure do |config|
config.credentials = "/path/to/credentials.json"
config.timeout = 10_000
end
```

Finally, you can override the configuration for each client instance. See the
next section on [Creating Clients](#creating-clients) for details.

### Creating Clients

In older releases, to create a client object, you would use the
`Google::Cloud::Language.new` class method. Keyword arguments were available to
select a service version and to configure parameters such as credentials and
timeouts.

Wiht the 1.0 release, use the `Google::Cloud::Language.language_service` class
With the 1.0 release, use the `Google::Cloud::Language.language_service` class
method to create a client object. You may select a service version using the
`:version` keyword argument. However, other configuration parameters should be
set in a configuration block when you create the client.
Expand All @@ -111,7 +127,7 @@ set some configuration parameters, then the default configuration is used. See

### Passing Arguments

In older releases, certain required arguments would be passed as positional
In older releases, required arguments would be passed as positional method
arguments, while most optional arguments would be passed as keyword arguments.

With the 1.0 release, all RPC arguments are passed as keyword arguments,
Expand All @@ -133,7 +149,7 @@ response = client.analyze_sentiment document, encoding_type: encoding

New:
```
client = Google::Cloud::Language.new
client = Google::Cloud::Language.language_service
document = {
content: "I love API calls!",
Expand All @@ -150,7 +166,7 @@ as a hash or as a protocol buffer.

New:
```
client = Google::Cloud::Language.new
client = Google::Cloud::Language.language_service
request = Google::Cloud::Language::V1::AnalyzeSentimentRequest.new(
document: {
Expand Down Expand Up @@ -184,7 +200,7 @@ response = client.analyze_sentiment document, options: options

New:
```
client = Google::Cloud::Language.new
client = Google::Cloud::Language.language_service
document = {
content: "I love API calls!",
Expand All @@ -209,9 +225,11 @@ In the 1.0 release, the client object is of class
Note that most users will use the `Google::Cloud::Language.language_service`
factory method to create instances of the client object, so you may not need to
reference the actual class directly.
See [Creating Clients](#creating-clients).

In older releases, the credentials object was of class
`Google::Cloud::Language::V1::Credentials`.
In the 1.0 release, the credentials object is of class
`Google::Cloud::Language::V1::LanguageService::Credentials`.
Again, most users will not need to reference this class directly.
See [Client Configuration](#client-configuration).
7 changes: 4 additions & 3 deletions google-cloud-language/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ $ gem install google-cloud-language
## Migrating from 0.x versions

The 1.0 release of the google-cloud-language client is a significant upgrade
based on a next-gen code generator. If you have used earlier versions of this
library, there have been a number of changes that may require updates to
calling code. See the MIGRATING.md document for more information.
based on a [next-gen code generator](https://github.com/googleapis/gapic-generator-ruby),
and includes substantial interface changes. Existing code written for earlier
versions of this library will likely require updates to use this version.
See the {file:MIGRATING.md MIGRATING.md} document for more information.

## Enabling Logging

Expand Down
30 changes: 21 additions & 9 deletions google-cloud-language/lib/google/cloud/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,28 @@ def self.language_service version: :v1, &block
#
# The following configuration parameters are supported:
#
# * `credentials` - (String, Hash, Google::Auth::Credentials) The path to the keyfile as a String, the contents of
# the keyfile as a Hash, or a Google::Auth::Credentials object.
# * `lib_name` (String)
# * `lib_version` (String)
# * `interceptors` (Array)
# * `timeout` - (Integer) Default timeout to use in requests.
# * `metadata` (Hash)
# * `retry_policy` (Hash, Proc)
# * `credentials` (*type:* `String, Hash, Google::Auth::Credentials`) -
# The path to the keyfile as a String, the contents of the keyfile as a
# Hash, or a Google::Auth::Credentials object.
# * `lib_name` (*type:* `String`) -
# The library name as recorded in instrumentation and logging.
# * `lib_version` (*type:* `String`) -
# The library version as recorded in instrumentation and logging.
# * `interceptors` (*type:* `Array<GRPC::ClientInterceptor>`) -
# An array of interceptors that are run before calls are executed.
# * `timeout` (*type:* `Integer`) -
# Default timeout in milliseconds.
# * `metadata` (*type:* `Hash{Symbol=>String}`) -
# Additional gRPC headers to be sent with the call.
# * `retry_policy` (*type:* `Hash`) -
# The retry policy. The value is a hash with the following keys:
# * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
# * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
# * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
# * `:retry_codes` (*type:* `Array<String>`) -
# The error codes that should trigger a retry.
#
# @return [Google::Cloud::Config] The configuration object the Google::Cloud::Language library uses.
# @return [Google::Cloud::Config] The default configuration used by this library
#
def self.configure
yield Google::Cloud.configure.language if block_given?
Expand Down

0 comments on commit 5c289b6

Please sign in to comment.