google-cloud-language-v2 0.a → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,656 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2023 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/language/v2/language_service_pb"
21
+ require "google/cloud/language/v2/language_service/rest/service_stub"
22
+
23
+ module Google
24
+ module Cloud
25
+ module Language
26
+ module V2
27
+ module LanguageService
28
+ module Rest
29
+ ##
30
+ # REST client for the LanguageService service.
31
+ #
32
+ # Provides text analysis operations such as sentiment analysis and entity
33
+ # recognition.
34
+ #
35
+ class Client
36
+ # @private
37
+ attr_reader :language_service_stub
38
+
39
+ ##
40
+ # Configure the LanguageService Client class.
41
+ #
42
+ # See {::Google::Cloud::Language::V2::LanguageService::Rest::Client::Configuration}
43
+ # for a description of the configuration fields.
44
+ #
45
+ # @example
46
+ #
47
+ # # Modify the configuration for all LanguageService clients
48
+ # ::Google::Cloud::Language::V2::LanguageService::Rest::Client.configure do |config|
49
+ # config.timeout = 10.0
50
+ # end
51
+ #
52
+ # @yield [config] Configure the Client client.
53
+ # @yieldparam config [Client::Configuration]
54
+ #
55
+ # @return [Client::Configuration]
56
+ #
57
+ def self.configure
58
+ @configure ||= begin
59
+ namespace = ["Google", "Cloud", "Language", "V2"]
60
+ parent_config = while namespace.any?
61
+ parent_name = namespace.join "::"
62
+ parent_const = const_get parent_name
63
+ break parent_const.configure if parent_const.respond_to? :configure
64
+ namespace.pop
65
+ end
66
+ default_config = Client::Configuration.new parent_config
67
+
68
+ default_config.rpcs.analyze_sentiment.timeout = 600.0
69
+ default_config.rpcs.analyze_sentiment.retry_policy = {
70
+ initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [4, 14]
71
+ }
72
+
73
+ default_config.rpcs.analyze_entities.timeout = 600.0
74
+ default_config.rpcs.analyze_entities.retry_policy = {
75
+ initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [4, 14]
76
+ }
77
+
78
+ default_config.rpcs.classify_text.timeout = 600.0
79
+ default_config.rpcs.classify_text.retry_policy = {
80
+ initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [4, 14]
81
+ }
82
+
83
+ default_config.rpcs.moderate_text.timeout = 600.0
84
+ default_config.rpcs.moderate_text.retry_policy = {
85
+ initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [4, 14]
86
+ }
87
+
88
+ default_config.rpcs.annotate_text.timeout = 600.0
89
+ default_config.rpcs.annotate_text.retry_policy = {
90
+ initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [4, 14]
91
+ }
92
+
93
+ default_config
94
+ end
95
+ yield @configure if block_given?
96
+ @configure
97
+ end
98
+
99
+ ##
100
+ # Configure the LanguageService Client instance.
101
+ #
102
+ # The configuration is set to the derived mode, meaning that values can be changed,
103
+ # but structural changes (adding new fields, etc.) are not allowed. Structural changes
104
+ # should be made on {Client.configure}.
105
+ #
106
+ # See {::Google::Cloud::Language::V2::LanguageService::Rest::Client::Configuration}
107
+ # for a description of the configuration fields.
108
+ #
109
+ # @yield [config] Configure the Client client.
110
+ # @yieldparam config [Client::Configuration]
111
+ #
112
+ # @return [Client::Configuration]
113
+ #
114
+ def configure
115
+ yield @config if block_given?
116
+ @config
117
+ end
118
+
119
+ ##
120
+ # Create a new LanguageService REST client object.
121
+ #
122
+ # @example
123
+ #
124
+ # # Create a client using the default configuration
125
+ # client = ::Google::Cloud::Language::V2::LanguageService::Rest::Client.new
126
+ #
127
+ # # Create a client using a custom configuration
128
+ # client = ::Google::Cloud::Language::V2::LanguageService::Rest::Client.new do |config|
129
+ # config.timeout = 10.0
130
+ # end
131
+ #
132
+ # @yield [config] Configure the LanguageService client.
133
+ # @yieldparam config [Client::Configuration]
134
+ #
135
+ def initialize
136
+ # Create the configuration object
137
+ @config = Configuration.new Client.configure
138
+
139
+ # Yield the configuration if needed
140
+ yield @config if block_given?
141
+
142
+ # Create credentials
143
+ credentials = @config.credentials
144
+ # Use self-signed JWT if the endpoint is unchanged from default,
145
+ # but only if the default endpoint does not have a region prefix.
146
+ enable_self_signed_jwt = @config.endpoint == Configuration::DEFAULT_ENDPOINT &&
147
+ !@config.endpoint.split(".").first.include?("-")
148
+ credentials ||= Credentials.default scope: @config.scope,
149
+ enable_self_signed_jwt: enable_self_signed_jwt
150
+ if credentials.is_a?(::String) || credentials.is_a?(::Hash)
151
+ credentials = Credentials.new credentials, scope: @config.scope
152
+ end
153
+
154
+ @quota_project_id = @config.quota_project
155
+ @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id
156
+
157
+ @language_service_stub = ::Google::Cloud::Language::V2::LanguageService::Rest::ServiceStub.new endpoint: @config.endpoint, credentials: credentials
158
+ end
159
+
160
+ # Service calls
161
+
162
+ ##
163
+ # Analyzes the sentiment of the provided text.
164
+ #
165
+ # @overload analyze_sentiment(request, options = nil)
166
+ # Pass arguments to `analyze_sentiment` via a request object, either of type
167
+ # {::Google::Cloud::Language::V2::AnalyzeSentimentRequest} or an equivalent Hash.
168
+ #
169
+ # @param request [::Google::Cloud::Language::V2::AnalyzeSentimentRequest, ::Hash]
170
+ # A request object representing the call parameters. Required. To specify no
171
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
172
+ # @param options [::Gapic::CallOptions, ::Hash]
173
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
174
+ #
175
+ # @overload analyze_sentiment(document: nil, encoding_type: nil)
176
+ # Pass arguments to `analyze_sentiment` via keyword arguments. Note that at
177
+ # least one keyword argument is required. To specify no parameters, or to keep all
178
+ # the default parameter values, pass an empty Hash as a request object (see above).
179
+ #
180
+ # @param document [::Google::Cloud::Language::V2::Document, ::Hash]
181
+ # Required. Input document.
182
+ # @param encoding_type [::Google::Cloud::Language::V2::EncodingType]
183
+ # The encoding type used by the API to calculate sentence offsets.
184
+ # @yield [result, operation] Access the result along with the TransportOperation object
185
+ # @yieldparam result [::Google::Cloud::Language::V2::AnalyzeSentimentResponse]
186
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
187
+ #
188
+ # @return [::Google::Cloud::Language::V2::AnalyzeSentimentResponse]
189
+ #
190
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
191
+ def analyze_sentiment request, options = nil
192
+ raise ::ArgumentError, "request must be provided" if request.nil?
193
+
194
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V2::AnalyzeSentimentRequest
195
+
196
+ # Converts hash and nil to an options object
197
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
198
+
199
+ # Customize the options with defaults
200
+ call_metadata = @config.rpcs.analyze_sentiment.metadata.to_h
201
+
202
+ # Set x-goog-api-client and x-goog-user-project headers
203
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
204
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
205
+ gapic_version: ::Google::Cloud::Language::V2::VERSION,
206
+ transports_version_send: [:rest]
207
+
208
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
209
+
210
+ options.apply_defaults timeout: @config.rpcs.analyze_sentiment.timeout,
211
+ metadata: call_metadata,
212
+ retry_policy: @config.rpcs.analyze_sentiment.retry_policy
213
+
214
+ options.apply_defaults timeout: @config.timeout,
215
+ metadata: @config.metadata,
216
+ retry_policy: @config.retry_policy
217
+
218
+ @language_service_stub.analyze_sentiment request, options do |result, operation|
219
+ yield result, operation if block_given?
220
+ return result
221
+ end
222
+ rescue ::Gapic::Rest::Error => e
223
+ raise ::Google::Cloud::Error.from_error(e)
224
+ end
225
+
226
+ ##
227
+ # Finds named entities (currently proper names and common nouns) in the text
228
+ # along with entity types, probability, mentions for each entity, and
229
+ # other properties.
230
+ #
231
+ # @overload analyze_entities(request, options = nil)
232
+ # Pass arguments to `analyze_entities` via a request object, either of type
233
+ # {::Google::Cloud::Language::V2::AnalyzeEntitiesRequest} or an equivalent Hash.
234
+ #
235
+ # @param request [::Google::Cloud::Language::V2::AnalyzeEntitiesRequest, ::Hash]
236
+ # A request object representing the call parameters. Required. To specify no
237
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
238
+ # @param options [::Gapic::CallOptions, ::Hash]
239
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
240
+ #
241
+ # @overload analyze_entities(document: nil, encoding_type: nil)
242
+ # Pass arguments to `analyze_entities` via keyword arguments. Note that at
243
+ # least one keyword argument is required. To specify no parameters, or to keep all
244
+ # the default parameter values, pass an empty Hash as a request object (see above).
245
+ #
246
+ # @param document [::Google::Cloud::Language::V2::Document, ::Hash]
247
+ # Required. Input document.
248
+ # @param encoding_type [::Google::Cloud::Language::V2::EncodingType]
249
+ # The encoding type used by the API to calculate offsets.
250
+ # @yield [result, operation] Access the result along with the TransportOperation object
251
+ # @yieldparam result [::Google::Cloud::Language::V2::AnalyzeEntitiesResponse]
252
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
253
+ #
254
+ # @return [::Google::Cloud::Language::V2::AnalyzeEntitiesResponse]
255
+ #
256
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
257
+ def analyze_entities request, options = nil
258
+ raise ::ArgumentError, "request must be provided" if request.nil?
259
+
260
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V2::AnalyzeEntitiesRequest
261
+
262
+ # Converts hash and nil to an options object
263
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
264
+
265
+ # Customize the options with defaults
266
+ call_metadata = @config.rpcs.analyze_entities.metadata.to_h
267
+
268
+ # Set x-goog-api-client and x-goog-user-project headers
269
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
270
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
271
+ gapic_version: ::Google::Cloud::Language::V2::VERSION,
272
+ transports_version_send: [:rest]
273
+
274
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
275
+
276
+ options.apply_defaults timeout: @config.rpcs.analyze_entities.timeout,
277
+ metadata: call_metadata,
278
+ retry_policy: @config.rpcs.analyze_entities.retry_policy
279
+
280
+ options.apply_defaults timeout: @config.timeout,
281
+ metadata: @config.metadata,
282
+ retry_policy: @config.retry_policy
283
+
284
+ @language_service_stub.analyze_entities request, options do |result, operation|
285
+ yield result, operation if block_given?
286
+ return result
287
+ end
288
+ rescue ::Gapic::Rest::Error => e
289
+ raise ::Google::Cloud::Error.from_error(e)
290
+ end
291
+
292
+ ##
293
+ # Classifies a document into categories.
294
+ #
295
+ # @overload classify_text(request, options = nil)
296
+ # Pass arguments to `classify_text` via a request object, either of type
297
+ # {::Google::Cloud::Language::V2::ClassifyTextRequest} or an equivalent Hash.
298
+ #
299
+ # @param request [::Google::Cloud::Language::V2::ClassifyTextRequest, ::Hash]
300
+ # A request object representing the call parameters. Required. To specify no
301
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
302
+ # @param options [::Gapic::CallOptions, ::Hash]
303
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
304
+ #
305
+ # @overload classify_text(document: nil)
306
+ # Pass arguments to `classify_text` via keyword arguments. Note that at
307
+ # least one keyword argument is required. To specify no parameters, or to keep all
308
+ # the default parameter values, pass an empty Hash as a request object (see above).
309
+ #
310
+ # @param document [::Google::Cloud::Language::V2::Document, ::Hash]
311
+ # Required. Input document.
312
+ # @yield [result, operation] Access the result along with the TransportOperation object
313
+ # @yieldparam result [::Google::Cloud::Language::V2::ClassifyTextResponse]
314
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
315
+ #
316
+ # @return [::Google::Cloud::Language::V2::ClassifyTextResponse]
317
+ #
318
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
319
+ def classify_text request, options = nil
320
+ raise ::ArgumentError, "request must be provided" if request.nil?
321
+
322
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V2::ClassifyTextRequest
323
+
324
+ # Converts hash and nil to an options object
325
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
326
+
327
+ # Customize the options with defaults
328
+ call_metadata = @config.rpcs.classify_text.metadata.to_h
329
+
330
+ # Set x-goog-api-client and x-goog-user-project headers
331
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
332
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
333
+ gapic_version: ::Google::Cloud::Language::V2::VERSION,
334
+ transports_version_send: [:rest]
335
+
336
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
337
+
338
+ options.apply_defaults timeout: @config.rpcs.classify_text.timeout,
339
+ metadata: call_metadata,
340
+ retry_policy: @config.rpcs.classify_text.retry_policy
341
+
342
+ options.apply_defaults timeout: @config.timeout,
343
+ metadata: @config.metadata,
344
+ retry_policy: @config.retry_policy
345
+
346
+ @language_service_stub.classify_text request, options do |result, operation|
347
+ yield result, operation if block_given?
348
+ return result
349
+ end
350
+ rescue ::Gapic::Rest::Error => e
351
+ raise ::Google::Cloud::Error.from_error(e)
352
+ end
353
+
354
+ ##
355
+ # Moderates a document for harmful and sensitive categories.
356
+ #
357
+ # @overload moderate_text(request, options = nil)
358
+ # Pass arguments to `moderate_text` via a request object, either of type
359
+ # {::Google::Cloud::Language::V2::ModerateTextRequest} or an equivalent Hash.
360
+ #
361
+ # @param request [::Google::Cloud::Language::V2::ModerateTextRequest, ::Hash]
362
+ # A request object representing the call parameters. Required. To specify no
363
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
364
+ # @param options [::Gapic::CallOptions, ::Hash]
365
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
366
+ #
367
+ # @overload moderate_text(document: nil)
368
+ # Pass arguments to `moderate_text` via keyword arguments. Note that at
369
+ # least one keyword argument is required. To specify no parameters, or to keep all
370
+ # the default parameter values, pass an empty Hash as a request object (see above).
371
+ #
372
+ # @param document [::Google::Cloud::Language::V2::Document, ::Hash]
373
+ # Required. Input document.
374
+ # @yield [result, operation] Access the result along with the TransportOperation object
375
+ # @yieldparam result [::Google::Cloud::Language::V2::ModerateTextResponse]
376
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
377
+ #
378
+ # @return [::Google::Cloud::Language::V2::ModerateTextResponse]
379
+ #
380
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
381
+ def moderate_text request, options = nil
382
+ raise ::ArgumentError, "request must be provided" if request.nil?
383
+
384
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V2::ModerateTextRequest
385
+
386
+ # Converts hash and nil to an options object
387
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
388
+
389
+ # Customize the options with defaults
390
+ call_metadata = @config.rpcs.moderate_text.metadata.to_h
391
+
392
+ # Set x-goog-api-client and x-goog-user-project headers
393
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
394
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
395
+ gapic_version: ::Google::Cloud::Language::V2::VERSION,
396
+ transports_version_send: [:rest]
397
+
398
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
399
+
400
+ options.apply_defaults timeout: @config.rpcs.moderate_text.timeout,
401
+ metadata: call_metadata,
402
+ retry_policy: @config.rpcs.moderate_text.retry_policy
403
+
404
+ options.apply_defaults timeout: @config.timeout,
405
+ metadata: @config.metadata,
406
+ retry_policy: @config.retry_policy
407
+
408
+ @language_service_stub.moderate_text request, options do |result, operation|
409
+ yield result, operation if block_given?
410
+ return result
411
+ end
412
+ rescue ::Gapic::Rest::Error => e
413
+ raise ::Google::Cloud::Error.from_error(e)
414
+ end
415
+
416
+ ##
417
+ # A convenience method that provides all features in one call.
418
+ #
419
+ # @overload annotate_text(request, options = nil)
420
+ # Pass arguments to `annotate_text` via a request object, either of type
421
+ # {::Google::Cloud::Language::V2::AnnotateTextRequest} or an equivalent Hash.
422
+ #
423
+ # @param request [::Google::Cloud::Language::V2::AnnotateTextRequest, ::Hash]
424
+ # A request object representing the call parameters. Required. To specify no
425
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
426
+ # @param options [::Gapic::CallOptions, ::Hash]
427
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
428
+ #
429
+ # @overload annotate_text(document: nil, features: nil, encoding_type: nil)
430
+ # Pass arguments to `annotate_text` via keyword arguments. Note that at
431
+ # least one keyword argument is required. To specify no parameters, or to keep all
432
+ # the default parameter values, pass an empty Hash as a request object (see above).
433
+ #
434
+ # @param document [::Google::Cloud::Language::V2::Document, ::Hash]
435
+ # Required. Input document.
436
+ # @param features [::Google::Cloud::Language::V2::AnnotateTextRequest::Features, ::Hash]
437
+ # Required. The enabled features.
438
+ # @param encoding_type [::Google::Cloud::Language::V2::EncodingType]
439
+ # The encoding type used by the API to calculate offsets.
440
+ # @yield [result, operation] Access the result along with the TransportOperation object
441
+ # @yieldparam result [::Google::Cloud::Language::V2::AnnotateTextResponse]
442
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
443
+ #
444
+ # @return [::Google::Cloud::Language::V2::AnnotateTextResponse]
445
+ #
446
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
447
+ def annotate_text request, options = nil
448
+ raise ::ArgumentError, "request must be provided" if request.nil?
449
+
450
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V2::AnnotateTextRequest
451
+
452
+ # Converts hash and nil to an options object
453
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
454
+
455
+ # Customize the options with defaults
456
+ call_metadata = @config.rpcs.annotate_text.metadata.to_h
457
+
458
+ # Set x-goog-api-client and x-goog-user-project headers
459
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
460
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
461
+ gapic_version: ::Google::Cloud::Language::V2::VERSION,
462
+ transports_version_send: [:rest]
463
+
464
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
465
+
466
+ options.apply_defaults timeout: @config.rpcs.annotate_text.timeout,
467
+ metadata: call_metadata,
468
+ retry_policy: @config.rpcs.annotate_text.retry_policy
469
+
470
+ options.apply_defaults timeout: @config.timeout,
471
+ metadata: @config.metadata,
472
+ retry_policy: @config.retry_policy
473
+
474
+ @language_service_stub.annotate_text request, options do |result, operation|
475
+ yield result, operation if block_given?
476
+ return result
477
+ end
478
+ rescue ::Gapic::Rest::Error => e
479
+ raise ::Google::Cloud::Error.from_error(e)
480
+ end
481
+
482
+ ##
483
+ # Configuration class for the LanguageService REST API.
484
+ #
485
+ # This class represents the configuration for LanguageService REST,
486
+ # providing control over timeouts, retry behavior, logging, transport
487
+ # parameters, and other low-level controls. Certain parameters can also be
488
+ # applied individually to specific RPCs. See
489
+ # {::Google::Cloud::Language::V2::LanguageService::Rest::Client::Configuration::Rpcs}
490
+ # for a list of RPCs that can be configured independently.
491
+ #
492
+ # Configuration can be applied globally to all clients, or to a single client
493
+ # on construction.
494
+ #
495
+ # @example
496
+ #
497
+ # # Modify the global config, setting the timeout for
498
+ # # analyze_sentiment to 20 seconds,
499
+ # # and all remaining timeouts to 10 seconds.
500
+ # ::Google::Cloud::Language::V2::LanguageService::Rest::Client.configure do |config|
501
+ # config.timeout = 10.0
502
+ # config.rpcs.analyze_sentiment.timeout = 20.0
503
+ # end
504
+ #
505
+ # # Apply the above configuration only to a new client.
506
+ # client = ::Google::Cloud::Language::V2::LanguageService::Rest::Client.new do |config|
507
+ # config.timeout = 10.0
508
+ # config.rpcs.analyze_sentiment.timeout = 20.0
509
+ # end
510
+ #
511
+ # @!attribute [rw] endpoint
512
+ # The hostname or hostname:port of the service endpoint.
513
+ # Defaults to `"language.googleapis.com"`.
514
+ # @return [::String]
515
+ # @!attribute [rw] credentials
516
+ # Credentials to send with calls. You may provide any of the following types:
517
+ # * (`String`) The path to a service account key file in JSON format
518
+ # * (`Hash`) A service account key as a Hash
519
+ # * (`Google::Auth::Credentials`) A googleauth credentials object
520
+ # (see the [googleauth docs](https://rubydoc.info/gems/googleauth/Google/Auth/Credentials))
521
+ # * (`Signet::OAuth2::Client`) A signet oauth2 client object
522
+ # (see the [signet docs](https://rubydoc.info/gems/signet/Signet/OAuth2/Client))
523
+ # * (`nil`) indicating no credentials
524
+ # @return [::Object]
525
+ # @!attribute [rw] scope
526
+ # The OAuth scopes
527
+ # @return [::Array<::String>]
528
+ # @!attribute [rw] lib_name
529
+ # The library name as recorded in instrumentation and logging
530
+ # @return [::String]
531
+ # @!attribute [rw] lib_version
532
+ # The library version as recorded in instrumentation and logging
533
+ # @return [::String]
534
+ # @!attribute [rw] timeout
535
+ # The call timeout in seconds.
536
+ # @return [::Numeric]
537
+ # @!attribute [rw] metadata
538
+ # Additional headers to be sent with the call.
539
+ # @return [::Hash{::Symbol=>::String}]
540
+ # @!attribute [rw] retry_policy
541
+ # The retry policy. The value is a hash with the following keys:
542
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
543
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
544
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
545
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
546
+ # trigger a retry.
547
+ # @return [::Hash]
548
+ # @!attribute [rw] quota_project
549
+ # A separate project against which to charge quota.
550
+ # @return [::String]
551
+ #
552
+ class Configuration
553
+ extend ::Gapic::Config
554
+
555
+ DEFAULT_ENDPOINT = "language.googleapis.com"
556
+
557
+ config_attr :endpoint, DEFAULT_ENDPOINT, ::String
558
+ config_attr :credentials, nil do |value|
559
+ allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
560
+ allowed.any? { |klass| klass === value }
561
+ end
562
+ config_attr :scope, nil, ::String, ::Array, nil
563
+ config_attr :lib_name, nil, ::String, nil
564
+ config_attr :lib_version, nil, ::String, nil
565
+ config_attr :timeout, nil, ::Numeric, nil
566
+ config_attr :metadata, nil, ::Hash, nil
567
+ config_attr :retry_policy, nil, ::Hash, ::Proc, nil
568
+ config_attr :quota_project, nil, ::String, nil
569
+
570
+ # @private
571
+ def initialize parent_config = nil
572
+ @parent_config = parent_config unless parent_config.nil?
573
+
574
+ yield self if block_given?
575
+ end
576
+
577
+ ##
578
+ # Configurations for individual RPCs
579
+ # @return [Rpcs]
580
+ #
581
+ def rpcs
582
+ @rpcs ||= begin
583
+ parent_rpcs = nil
584
+ parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs)
585
+ Rpcs.new parent_rpcs
586
+ end
587
+ end
588
+
589
+ ##
590
+ # Configuration RPC class for the LanguageService API.
591
+ #
592
+ # Includes fields providing the configuration for each RPC in this service.
593
+ # Each configuration object is of type `Gapic::Config::Method` and includes
594
+ # the following configuration fields:
595
+ #
596
+ # * `timeout` (*type:* `Numeric`) - The call timeout in seconds
597
+ # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional headers
598
+ # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
599
+ # include the following keys:
600
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
601
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
602
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
603
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
604
+ # trigger a retry.
605
+ #
606
+ class Rpcs
607
+ ##
608
+ # RPC-specific configuration for `analyze_sentiment`
609
+ # @return [::Gapic::Config::Method]
610
+ #
611
+ attr_reader :analyze_sentiment
612
+ ##
613
+ # RPC-specific configuration for `analyze_entities`
614
+ # @return [::Gapic::Config::Method]
615
+ #
616
+ attr_reader :analyze_entities
617
+ ##
618
+ # RPC-specific configuration for `classify_text`
619
+ # @return [::Gapic::Config::Method]
620
+ #
621
+ attr_reader :classify_text
622
+ ##
623
+ # RPC-specific configuration for `moderate_text`
624
+ # @return [::Gapic::Config::Method]
625
+ #
626
+ attr_reader :moderate_text
627
+ ##
628
+ # RPC-specific configuration for `annotate_text`
629
+ # @return [::Gapic::Config::Method]
630
+ #
631
+ attr_reader :annotate_text
632
+
633
+ # @private
634
+ def initialize parent_rpcs = nil
635
+ analyze_sentiment_config = parent_rpcs.analyze_sentiment if parent_rpcs.respond_to? :analyze_sentiment
636
+ @analyze_sentiment = ::Gapic::Config::Method.new analyze_sentiment_config
637
+ analyze_entities_config = parent_rpcs.analyze_entities if parent_rpcs.respond_to? :analyze_entities
638
+ @analyze_entities = ::Gapic::Config::Method.new analyze_entities_config
639
+ classify_text_config = parent_rpcs.classify_text if parent_rpcs.respond_to? :classify_text
640
+ @classify_text = ::Gapic::Config::Method.new classify_text_config
641
+ moderate_text_config = parent_rpcs.moderate_text if parent_rpcs.respond_to? :moderate_text
642
+ @moderate_text = ::Gapic::Config::Method.new moderate_text_config
643
+ annotate_text_config = parent_rpcs.annotate_text if parent_rpcs.respond_to? :annotate_text
644
+ @annotate_text = ::Gapic::Config::Method.new annotate_text_config
645
+
646
+ yield self if block_given?
647
+ end
648
+ end
649
+ end
650
+ end
651
+ end
652
+ end
653
+ end
654
+ end
655
+ end
656
+ end