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

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,736 @@
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
+ #
192
+ # @example Basic example
193
+ # require "google/cloud/language/v2"
194
+ #
195
+ # # Create a client object. The client can be reused for multiple calls.
196
+ # client = Google::Cloud::Language::V2::LanguageService::Rest::Client.new
197
+ #
198
+ # # Create a request. To set request fields, pass in keyword arguments.
199
+ # request = Google::Cloud::Language::V2::AnalyzeSentimentRequest.new
200
+ #
201
+ # # Call the analyze_sentiment method.
202
+ # result = client.analyze_sentiment request
203
+ #
204
+ # # The returned object is of type Google::Cloud::Language::V2::AnalyzeSentimentResponse.
205
+ # p result
206
+ #
207
+ def analyze_sentiment request, options = nil
208
+ raise ::ArgumentError, "request must be provided" if request.nil?
209
+
210
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V2::AnalyzeSentimentRequest
211
+
212
+ # Converts hash and nil to an options object
213
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
214
+
215
+ # Customize the options with defaults
216
+ call_metadata = @config.rpcs.analyze_sentiment.metadata.to_h
217
+
218
+ # Set x-goog-api-client and x-goog-user-project headers
219
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
220
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
221
+ gapic_version: ::Google::Cloud::Language::V2::VERSION,
222
+ transports_version_send: [:rest]
223
+
224
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
225
+
226
+ options.apply_defaults timeout: @config.rpcs.analyze_sentiment.timeout,
227
+ metadata: call_metadata,
228
+ retry_policy: @config.rpcs.analyze_sentiment.retry_policy
229
+
230
+ options.apply_defaults timeout: @config.timeout,
231
+ metadata: @config.metadata,
232
+ retry_policy: @config.retry_policy
233
+
234
+ @language_service_stub.analyze_sentiment request, options do |result, operation|
235
+ yield result, operation if block_given?
236
+ return result
237
+ end
238
+ rescue ::Gapic::Rest::Error => e
239
+ raise ::Google::Cloud::Error.from_error(e)
240
+ end
241
+
242
+ ##
243
+ # Finds named entities (currently proper names and common nouns) in the text
244
+ # along with entity types, probability, mentions for each entity, and
245
+ # other properties.
246
+ #
247
+ # @overload analyze_entities(request, options = nil)
248
+ # Pass arguments to `analyze_entities` via a request object, either of type
249
+ # {::Google::Cloud::Language::V2::AnalyzeEntitiesRequest} or an equivalent Hash.
250
+ #
251
+ # @param request [::Google::Cloud::Language::V2::AnalyzeEntitiesRequest, ::Hash]
252
+ # A request object representing the call parameters. Required. To specify no
253
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
254
+ # @param options [::Gapic::CallOptions, ::Hash]
255
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
256
+ #
257
+ # @overload analyze_entities(document: nil, encoding_type: nil)
258
+ # Pass arguments to `analyze_entities` via keyword arguments. Note that at
259
+ # least one keyword argument is required. To specify no parameters, or to keep all
260
+ # the default parameter values, pass an empty Hash as a request object (see above).
261
+ #
262
+ # @param document [::Google::Cloud::Language::V2::Document, ::Hash]
263
+ # Required. Input document.
264
+ # @param encoding_type [::Google::Cloud::Language::V2::EncodingType]
265
+ # The encoding type used by the API to calculate offsets.
266
+ # @yield [result, operation] Access the result along with the TransportOperation object
267
+ # @yieldparam result [::Google::Cloud::Language::V2::AnalyzeEntitiesResponse]
268
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
269
+ #
270
+ # @return [::Google::Cloud::Language::V2::AnalyzeEntitiesResponse]
271
+ #
272
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
273
+ #
274
+ # @example Basic example
275
+ # require "google/cloud/language/v2"
276
+ #
277
+ # # Create a client object. The client can be reused for multiple calls.
278
+ # client = Google::Cloud::Language::V2::LanguageService::Rest::Client.new
279
+ #
280
+ # # Create a request. To set request fields, pass in keyword arguments.
281
+ # request = Google::Cloud::Language::V2::AnalyzeEntitiesRequest.new
282
+ #
283
+ # # Call the analyze_entities method.
284
+ # result = client.analyze_entities request
285
+ #
286
+ # # The returned object is of type Google::Cloud::Language::V2::AnalyzeEntitiesResponse.
287
+ # p result
288
+ #
289
+ def analyze_entities request, options = nil
290
+ raise ::ArgumentError, "request must be provided" if request.nil?
291
+
292
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V2::AnalyzeEntitiesRequest
293
+
294
+ # Converts hash and nil to an options object
295
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
296
+
297
+ # Customize the options with defaults
298
+ call_metadata = @config.rpcs.analyze_entities.metadata.to_h
299
+
300
+ # Set x-goog-api-client and x-goog-user-project headers
301
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
302
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
303
+ gapic_version: ::Google::Cloud::Language::V2::VERSION,
304
+ transports_version_send: [:rest]
305
+
306
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
307
+
308
+ options.apply_defaults timeout: @config.rpcs.analyze_entities.timeout,
309
+ metadata: call_metadata,
310
+ retry_policy: @config.rpcs.analyze_entities.retry_policy
311
+
312
+ options.apply_defaults timeout: @config.timeout,
313
+ metadata: @config.metadata,
314
+ retry_policy: @config.retry_policy
315
+
316
+ @language_service_stub.analyze_entities request, options do |result, operation|
317
+ yield result, operation if block_given?
318
+ return result
319
+ end
320
+ rescue ::Gapic::Rest::Error => e
321
+ raise ::Google::Cloud::Error.from_error(e)
322
+ end
323
+
324
+ ##
325
+ # Classifies a document into categories.
326
+ #
327
+ # @overload classify_text(request, options = nil)
328
+ # Pass arguments to `classify_text` via a request object, either of type
329
+ # {::Google::Cloud::Language::V2::ClassifyTextRequest} or an equivalent Hash.
330
+ #
331
+ # @param request [::Google::Cloud::Language::V2::ClassifyTextRequest, ::Hash]
332
+ # A request object representing the call parameters. Required. To specify no
333
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
334
+ # @param options [::Gapic::CallOptions, ::Hash]
335
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
336
+ #
337
+ # @overload classify_text(document: nil)
338
+ # Pass arguments to `classify_text` via keyword arguments. Note that at
339
+ # least one keyword argument is required. To specify no parameters, or to keep all
340
+ # the default parameter values, pass an empty Hash as a request object (see above).
341
+ #
342
+ # @param document [::Google::Cloud::Language::V2::Document, ::Hash]
343
+ # Required. Input document.
344
+ # @yield [result, operation] Access the result along with the TransportOperation object
345
+ # @yieldparam result [::Google::Cloud::Language::V2::ClassifyTextResponse]
346
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
347
+ #
348
+ # @return [::Google::Cloud::Language::V2::ClassifyTextResponse]
349
+ #
350
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
351
+ #
352
+ # @example Basic example
353
+ # require "google/cloud/language/v2"
354
+ #
355
+ # # Create a client object. The client can be reused for multiple calls.
356
+ # client = Google::Cloud::Language::V2::LanguageService::Rest::Client.new
357
+ #
358
+ # # Create a request. To set request fields, pass in keyword arguments.
359
+ # request = Google::Cloud::Language::V2::ClassifyTextRequest.new
360
+ #
361
+ # # Call the classify_text method.
362
+ # result = client.classify_text request
363
+ #
364
+ # # The returned object is of type Google::Cloud::Language::V2::ClassifyTextResponse.
365
+ # p result
366
+ #
367
+ def classify_text request, options = nil
368
+ raise ::ArgumentError, "request must be provided" if request.nil?
369
+
370
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V2::ClassifyTextRequest
371
+
372
+ # Converts hash and nil to an options object
373
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
374
+
375
+ # Customize the options with defaults
376
+ call_metadata = @config.rpcs.classify_text.metadata.to_h
377
+
378
+ # Set x-goog-api-client and x-goog-user-project headers
379
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
380
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
381
+ gapic_version: ::Google::Cloud::Language::V2::VERSION,
382
+ transports_version_send: [:rest]
383
+
384
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
385
+
386
+ options.apply_defaults timeout: @config.rpcs.classify_text.timeout,
387
+ metadata: call_metadata,
388
+ retry_policy: @config.rpcs.classify_text.retry_policy
389
+
390
+ options.apply_defaults timeout: @config.timeout,
391
+ metadata: @config.metadata,
392
+ retry_policy: @config.retry_policy
393
+
394
+ @language_service_stub.classify_text request, options do |result, operation|
395
+ yield result, operation if block_given?
396
+ return result
397
+ end
398
+ rescue ::Gapic::Rest::Error => e
399
+ raise ::Google::Cloud::Error.from_error(e)
400
+ end
401
+
402
+ ##
403
+ # Moderates a document for harmful and sensitive categories.
404
+ #
405
+ # @overload moderate_text(request, options = nil)
406
+ # Pass arguments to `moderate_text` via a request object, either of type
407
+ # {::Google::Cloud::Language::V2::ModerateTextRequest} or an equivalent Hash.
408
+ #
409
+ # @param request [::Google::Cloud::Language::V2::ModerateTextRequest, ::Hash]
410
+ # A request object representing the call parameters. Required. To specify no
411
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
412
+ # @param options [::Gapic::CallOptions, ::Hash]
413
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
414
+ #
415
+ # @overload moderate_text(document: nil)
416
+ # Pass arguments to `moderate_text` via keyword arguments. Note that at
417
+ # least one keyword argument is required. To specify no parameters, or to keep all
418
+ # the default parameter values, pass an empty Hash as a request object (see above).
419
+ #
420
+ # @param document [::Google::Cloud::Language::V2::Document, ::Hash]
421
+ # Required. Input document.
422
+ # @yield [result, operation] Access the result along with the TransportOperation object
423
+ # @yieldparam result [::Google::Cloud::Language::V2::ModerateTextResponse]
424
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
425
+ #
426
+ # @return [::Google::Cloud::Language::V2::ModerateTextResponse]
427
+ #
428
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
429
+ #
430
+ # @example Basic example
431
+ # require "google/cloud/language/v2"
432
+ #
433
+ # # Create a client object. The client can be reused for multiple calls.
434
+ # client = Google::Cloud::Language::V2::LanguageService::Rest::Client.new
435
+ #
436
+ # # Create a request. To set request fields, pass in keyword arguments.
437
+ # request = Google::Cloud::Language::V2::ModerateTextRequest.new
438
+ #
439
+ # # Call the moderate_text method.
440
+ # result = client.moderate_text request
441
+ #
442
+ # # The returned object is of type Google::Cloud::Language::V2::ModerateTextResponse.
443
+ # p result
444
+ #
445
+ def moderate_text request, options = nil
446
+ raise ::ArgumentError, "request must be provided" if request.nil?
447
+
448
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V2::ModerateTextRequest
449
+
450
+ # Converts hash and nil to an options object
451
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
452
+
453
+ # Customize the options with defaults
454
+ call_metadata = @config.rpcs.moderate_text.metadata.to_h
455
+
456
+ # Set x-goog-api-client and x-goog-user-project headers
457
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
458
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
459
+ gapic_version: ::Google::Cloud::Language::V2::VERSION,
460
+ transports_version_send: [:rest]
461
+
462
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
463
+
464
+ options.apply_defaults timeout: @config.rpcs.moderate_text.timeout,
465
+ metadata: call_metadata,
466
+ retry_policy: @config.rpcs.moderate_text.retry_policy
467
+
468
+ options.apply_defaults timeout: @config.timeout,
469
+ metadata: @config.metadata,
470
+ retry_policy: @config.retry_policy
471
+
472
+ @language_service_stub.moderate_text request, options do |result, operation|
473
+ yield result, operation if block_given?
474
+ return result
475
+ end
476
+ rescue ::Gapic::Rest::Error => e
477
+ raise ::Google::Cloud::Error.from_error(e)
478
+ end
479
+
480
+ ##
481
+ # A convenience method that provides all features in one call.
482
+ #
483
+ # @overload annotate_text(request, options = nil)
484
+ # Pass arguments to `annotate_text` via a request object, either of type
485
+ # {::Google::Cloud::Language::V2::AnnotateTextRequest} or an equivalent Hash.
486
+ #
487
+ # @param request [::Google::Cloud::Language::V2::AnnotateTextRequest, ::Hash]
488
+ # A request object representing the call parameters. Required. To specify no
489
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
490
+ # @param options [::Gapic::CallOptions, ::Hash]
491
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
492
+ #
493
+ # @overload annotate_text(document: nil, features: nil, encoding_type: nil)
494
+ # Pass arguments to `annotate_text` via keyword arguments. Note that at
495
+ # least one keyword argument is required. To specify no parameters, or to keep all
496
+ # the default parameter values, pass an empty Hash as a request object (see above).
497
+ #
498
+ # @param document [::Google::Cloud::Language::V2::Document, ::Hash]
499
+ # Required. Input document.
500
+ # @param features [::Google::Cloud::Language::V2::AnnotateTextRequest::Features, ::Hash]
501
+ # Required. The enabled features.
502
+ # @param encoding_type [::Google::Cloud::Language::V2::EncodingType]
503
+ # The encoding type used by the API to calculate offsets.
504
+ # @yield [result, operation] Access the result along with the TransportOperation object
505
+ # @yieldparam result [::Google::Cloud::Language::V2::AnnotateTextResponse]
506
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
507
+ #
508
+ # @return [::Google::Cloud::Language::V2::AnnotateTextResponse]
509
+ #
510
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
511
+ #
512
+ # @example Basic example
513
+ # require "google/cloud/language/v2"
514
+ #
515
+ # # Create a client object. The client can be reused for multiple calls.
516
+ # client = Google::Cloud::Language::V2::LanguageService::Rest::Client.new
517
+ #
518
+ # # Create a request. To set request fields, pass in keyword arguments.
519
+ # request = Google::Cloud::Language::V2::AnnotateTextRequest.new
520
+ #
521
+ # # Call the annotate_text method.
522
+ # result = client.annotate_text request
523
+ #
524
+ # # The returned object is of type Google::Cloud::Language::V2::AnnotateTextResponse.
525
+ # p result
526
+ #
527
+ def annotate_text request, options = nil
528
+ raise ::ArgumentError, "request must be provided" if request.nil?
529
+
530
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V2::AnnotateTextRequest
531
+
532
+ # Converts hash and nil to an options object
533
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
534
+
535
+ # Customize the options with defaults
536
+ call_metadata = @config.rpcs.annotate_text.metadata.to_h
537
+
538
+ # Set x-goog-api-client and x-goog-user-project headers
539
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
540
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
541
+ gapic_version: ::Google::Cloud::Language::V2::VERSION,
542
+ transports_version_send: [:rest]
543
+
544
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
545
+
546
+ options.apply_defaults timeout: @config.rpcs.annotate_text.timeout,
547
+ metadata: call_metadata,
548
+ retry_policy: @config.rpcs.annotate_text.retry_policy
549
+
550
+ options.apply_defaults timeout: @config.timeout,
551
+ metadata: @config.metadata,
552
+ retry_policy: @config.retry_policy
553
+
554
+ @language_service_stub.annotate_text request, options do |result, operation|
555
+ yield result, operation if block_given?
556
+ return result
557
+ end
558
+ rescue ::Gapic::Rest::Error => e
559
+ raise ::Google::Cloud::Error.from_error(e)
560
+ end
561
+
562
+ ##
563
+ # Configuration class for the LanguageService REST API.
564
+ #
565
+ # This class represents the configuration for LanguageService REST,
566
+ # providing control over timeouts, retry behavior, logging, transport
567
+ # parameters, and other low-level controls. Certain parameters can also be
568
+ # applied individually to specific RPCs. See
569
+ # {::Google::Cloud::Language::V2::LanguageService::Rest::Client::Configuration::Rpcs}
570
+ # for a list of RPCs that can be configured independently.
571
+ #
572
+ # Configuration can be applied globally to all clients, or to a single client
573
+ # on construction.
574
+ #
575
+ # @example
576
+ #
577
+ # # Modify the global config, setting the timeout for
578
+ # # analyze_sentiment to 20 seconds,
579
+ # # and all remaining timeouts to 10 seconds.
580
+ # ::Google::Cloud::Language::V2::LanguageService::Rest::Client.configure do |config|
581
+ # config.timeout = 10.0
582
+ # config.rpcs.analyze_sentiment.timeout = 20.0
583
+ # end
584
+ #
585
+ # # Apply the above configuration only to a new client.
586
+ # client = ::Google::Cloud::Language::V2::LanguageService::Rest::Client.new do |config|
587
+ # config.timeout = 10.0
588
+ # config.rpcs.analyze_sentiment.timeout = 20.0
589
+ # end
590
+ #
591
+ # @!attribute [rw] endpoint
592
+ # The hostname or hostname:port of the service endpoint.
593
+ # Defaults to `"language.googleapis.com"`.
594
+ # @return [::String]
595
+ # @!attribute [rw] credentials
596
+ # Credentials to send with calls. You may provide any of the following types:
597
+ # * (`String`) The path to a service account key file in JSON format
598
+ # * (`Hash`) A service account key as a Hash
599
+ # * (`Google::Auth::Credentials`) A googleauth credentials object
600
+ # (see the [googleauth docs](https://rubydoc.info/gems/googleauth/Google/Auth/Credentials))
601
+ # * (`Signet::OAuth2::Client`) A signet oauth2 client object
602
+ # (see the [signet docs](https://rubydoc.info/gems/signet/Signet/OAuth2/Client))
603
+ # * (`nil`) indicating no credentials
604
+ # @return [::Object]
605
+ # @!attribute [rw] scope
606
+ # The OAuth scopes
607
+ # @return [::Array<::String>]
608
+ # @!attribute [rw] lib_name
609
+ # The library name as recorded in instrumentation and logging
610
+ # @return [::String]
611
+ # @!attribute [rw] lib_version
612
+ # The library version as recorded in instrumentation and logging
613
+ # @return [::String]
614
+ # @!attribute [rw] timeout
615
+ # The call timeout in seconds.
616
+ # @return [::Numeric]
617
+ # @!attribute [rw] metadata
618
+ # Additional headers to be sent with the call.
619
+ # @return [::Hash{::Symbol=>::String}]
620
+ # @!attribute [rw] retry_policy
621
+ # The retry policy. The value is a hash with the following keys:
622
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
623
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
624
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
625
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
626
+ # trigger a retry.
627
+ # @return [::Hash]
628
+ # @!attribute [rw] quota_project
629
+ # A separate project against which to charge quota.
630
+ # @return [::String]
631
+ #
632
+ class Configuration
633
+ extend ::Gapic::Config
634
+
635
+ DEFAULT_ENDPOINT = "language.googleapis.com"
636
+
637
+ config_attr :endpoint, DEFAULT_ENDPOINT, ::String
638
+ config_attr :credentials, nil do |value|
639
+ allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
640
+ allowed.any? { |klass| klass === value }
641
+ end
642
+ config_attr :scope, nil, ::String, ::Array, nil
643
+ config_attr :lib_name, nil, ::String, nil
644
+ config_attr :lib_version, nil, ::String, nil
645
+ config_attr :timeout, nil, ::Numeric, nil
646
+ config_attr :metadata, nil, ::Hash, nil
647
+ config_attr :retry_policy, nil, ::Hash, ::Proc, nil
648
+ config_attr :quota_project, nil, ::String, nil
649
+
650
+ # @private
651
+ def initialize parent_config = nil
652
+ @parent_config = parent_config unless parent_config.nil?
653
+
654
+ yield self if block_given?
655
+ end
656
+
657
+ ##
658
+ # Configurations for individual RPCs
659
+ # @return [Rpcs]
660
+ #
661
+ def rpcs
662
+ @rpcs ||= begin
663
+ parent_rpcs = nil
664
+ parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs)
665
+ Rpcs.new parent_rpcs
666
+ end
667
+ end
668
+
669
+ ##
670
+ # Configuration RPC class for the LanguageService API.
671
+ #
672
+ # Includes fields providing the configuration for each RPC in this service.
673
+ # Each configuration object is of type `Gapic::Config::Method` and includes
674
+ # the following configuration fields:
675
+ #
676
+ # * `timeout` (*type:* `Numeric`) - The call timeout in seconds
677
+ # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional headers
678
+ # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
679
+ # include the following keys:
680
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
681
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
682
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
683
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
684
+ # trigger a retry.
685
+ #
686
+ class Rpcs
687
+ ##
688
+ # RPC-specific configuration for `analyze_sentiment`
689
+ # @return [::Gapic::Config::Method]
690
+ #
691
+ attr_reader :analyze_sentiment
692
+ ##
693
+ # RPC-specific configuration for `analyze_entities`
694
+ # @return [::Gapic::Config::Method]
695
+ #
696
+ attr_reader :analyze_entities
697
+ ##
698
+ # RPC-specific configuration for `classify_text`
699
+ # @return [::Gapic::Config::Method]
700
+ #
701
+ attr_reader :classify_text
702
+ ##
703
+ # RPC-specific configuration for `moderate_text`
704
+ # @return [::Gapic::Config::Method]
705
+ #
706
+ attr_reader :moderate_text
707
+ ##
708
+ # RPC-specific configuration for `annotate_text`
709
+ # @return [::Gapic::Config::Method]
710
+ #
711
+ attr_reader :annotate_text
712
+
713
+ # @private
714
+ def initialize parent_rpcs = nil
715
+ analyze_sentiment_config = parent_rpcs.analyze_sentiment if parent_rpcs.respond_to? :analyze_sentiment
716
+ @analyze_sentiment = ::Gapic::Config::Method.new analyze_sentiment_config
717
+ analyze_entities_config = parent_rpcs.analyze_entities if parent_rpcs.respond_to? :analyze_entities
718
+ @analyze_entities = ::Gapic::Config::Method.new analyze_entities_config
719
+ classify_text_config = parent_rpcs.classify_text if parent_rpcs.respond_to? :classify_text
720
+ @classify_text = ::Gapic::Config::Method.new classify_text_config
721
+ moderate_text_config = parent_rpcs.moderate_text if parent_rpcs.respond_to? :moderate_text
722
+ @moderate_text = ::Gapic::Config::Method.new moderate_text_config
723
+ annotate_text_config = parent_rpcs.annotate_text if parent_rpcs.respond_to? :annotate_text
724
+ @annotate_text = ::Gapic::Config::Method.new annotate_text_config
725
+
726
+ yield self if block_given?
727
+ end
728
+ end
729
+ end
730
+ end
731
+ end
732
+ end
733
+ end
734
+ end
735
+ end
736
+ end