lib/google/cloud/language/v2/language_service/rest/service_stub.rb in google-cloud-language-v2-0.5.1 vs lib/google/cloud/language/v2/language_service/rest/service_stub.rb in google-cloud-language-v2-0.6.0
- old
+ new
@@ -28,21 +28,24 @@
# REST service stub for the LanguageService service.
# Service stub contains baseline method implementations
# including transcoding, making the REST call, and deserialing the response.
#
class ServiceStub
- def initialize endpoint:, endpoint_template:, universe_domain:, credentials:
+ # @private
+ def initialize endpoint:, endpoint_template:, universe_domain:, credentials:, logger:
# These require statements are intentionally placed here to initialize
# the REST modules only when it's required.
require "gapic/rest"
@client_stub = ::Gapic::Rest::ClientStub.new endpoint: endpoint,
endpoint_template: endpoint_template,
universe_domain: universe_domain,
credentials: credentials,
numeric_enums: true,
- raise_faraday_errors: false
+ service_name: self.class,
+ raise_faraday_errors: false,
+ logger: logger
end
##
# The effective universe domain
#
@@ -60,10 +63,19 @@
def endpoint
@client_stub.endpoint
end
##
+ # The logger used for request/response debug logging.
+ #
+ # @return [Logger]
+ #
+ def logger stub: false
+ stub ? @client_stub.stub_logger : @client_stub.logger
+ end
+
+ ##
# Baseline implementation for the analyze_sentiment REST call
#
# @param request_pb [::Google::Cloud::Language::V2::AnalyzeSentimentRequest]
# A request object representing the call parameters. Required.
# @param options [::Gapic::CallOptions]
@@ -85,20 +97,22 @@
{}
end
response = @client_stub.make_http_request(
verb,
- uri: uri,
- body: body || "",
- params: query_string_params,
+ uri: uri,
+ body: body || "",
+ params: query_string_params,
+ method_name: "analyze_sentiment",
options: options
)
operation = ::Gapic::Rest::TransportOperation.new response
result = ::Google::Cloud::Language::V2::AnalyzeSentimentResponse.decode_json response.body, ignore_unknown_fields: true
-
- yield result, operation if block_given?
- result
+ catch :response do
+ yield result, operation if block_given?
+ result
+ end
end
##
# Baseline implementation for the analyze_entities REST call
#
@@ -123,20 +137,22 @@
{}
end
response = @client_stub.make_http_request(
verb,
- uri: uri,
- body: body || "",
- params: query_string_params,
+ uri: uri,
+ body: body || "",
+ params: query_string_params,
+ method_name: "analyze_entities",
options: options
)
operation = ::Gapic::Rest::TransportOperation.new response
result = ::Google::Cloud::Language::V2::AnalyzeEntitiesResponse.decode_json response.body, ignore_unknown_fields: true
-
- yield result, operation if block_given?
- result
+ catch :response do
+ yield result, operation if block_given?
+ result
+ end
end
##
# Baseline implementation for the classify_text REST call
#
@@ -161,20 +177,22 @@
{}
end
response = @client_stub.make_http_request(
verb,
- uri: uri,
- body: body || "",
- params: query_string_params,
+ uri: uri,
+ body: body || "",
+ params: query_string_params,
+ method_name: "classify_text",
options: options
)
operation = ::Gapic::Rest::TransportOperation.new response
result = ::Google::Cloud::Language::V2::ClassifyTextResponse.decode_json response.body, ignore_unknown_fields: true
-
- yield result, operation if block_given?
- result
+ catch :response do
+ yield result, operation if block_given?
+ result
+ end
end
##
# Baseline implementation for the moderate_text REST call
#
@@ -199,20 +217,22 @@
{}
end
response = @client_stub.make_http_request(
verb,
- uri: uri,
- body: body || "",
- params: query_string_params,
+ uri: uri,
+ body: body || "",
+ params: query_string_params,
+ method_name: "moderate_text",
options: options
)
operation = ::Gapic::Rest::TransportOperation.new response
result = ::Google::Cloud::Language::V2::ModerateTextResponse.decode_json response.body, ignore_unknown_fields: true
-
- yield result, operation if block_given?
- result
+ catch :response do
+ yield result, operation if block_given?
+ result
+ end
end
##
# Baseline implementation for the annotate_text REST call
#
@@ -237,19 +257,21 @@
{}
end
response = @client_stub.make_http_request(
verb,
- uri: uri,
- body: body || "",
- params: query_string_params,
+ uri: uri,
+ body: body || "",
+ params: query_string_params,
+ method_name: "annotate_text",
options: options
)
operation = ::Gapic::Rest::TransportOperation.new response
result = ::Google::Cloud::Language::V2::AnnotateTextResponse.decode_json response.body, ignore_unknown_fields: true
-
- yield result, operation if block_given?
- result
+ catch :response do
+ yield result, operation if block_given?
+ result
+ end
end
##
# @private
#