Class: Google::Cloud::Speech::V1::Speech::Rest::ServiceStub

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/speech/v1/speech/rest/service_stub.rb

Overview

REST service stub for the Speech service. Service stub contains baseline method implementations including transcoding, making the REST call, and deserialing the response.

Instance Method Summary collapse

Constructor Details

#initialize(endpoint:, endpoint_template:, universe_domain:, credentials:) ⇒ ServiceStub

Returns a new instance of ServiceStub.



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/google/cloud/speech/v1/speech/rest/service_stub.rb', line 33

def initialize endpoint:, endpoint_template:, universe_domain:, credentials:
  # 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
end

Instance Method Details

#endpointString

The effective endpoint

Returns:

  • (String)


60
61
62
# File 'lib/google/cloud/speech/v1/speech/rest/service_stub.rb', line 60

def endpoint
  @client_stub.endpoint
end

#long_running_recognize(request_pb, options = nil) {|result, operation| ... } ⇒ ::Google::Longrunning::Operation

Baseline implementation for the long_running_recognize REST call

Parameters:

Yields:

  • (result, operation)

    Access the result along with the TransportOperation object

Yield Parameters:

Returns:

Raises:

  • (::ArgumentError)


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/google/cloud/speech/v1/speech/rest/service_stub.rb', line 116

def long_running_recognize request_pb, options = nil
  raise ::ArgumentError, "request must be provided" if request_pb.nil?

  verb, uri, query_string_params, body = ServiceStub.transcode_long_running_recognize_request request_pb
  query_string_params = if query_string_params.any?
                          query_string_params.to_h { |p| p.split "=", 2 }
                        else
                          {}
                        end

  response = @client_stub.make_http_request(
    verb,
    uri:     uri,
    body:    body || "",
    params:  query_string_params,
    options: options
  )
  operation = ::Gapic::Rest::TransportOperation.new response
  result = ::Google::Longrunning::Operation.decode_json response.body, ignore_unknown_fields: true

  yield result, operation if block_given?
  result
end

#recognize(request_pb, options = nil) {|result, operation| ... } ⇒ ::Google::Cloud::Speech::V1::RecognizeResponse

Baseline implementation for the recognize REST call

Parameters:

  • request_pb (::Google::Cloud::Speech::V1::RecognizeRequest)

    A request object representing the call parameters. Required.

  • options (::Gapic::CallOptions) (defaults to: nil)

    Overrides the default settings for this call, e.g, timeout, retries etc. Optional.

Yields:

  • (result, operation)

    Access the result along with the TransportOperation object

Yield Parameters:

Returns:

Raises:

  • (::ArgumentError)


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/google/cloud/speech/v1/speech/rest/service_stub.rb', line 78

def recognize request_pb, options = nil
  raise ::ArgumentError, "request must be provided" if request_pb.nil?

  verb, uri, query_string_params, body = ServiceStub.transcode_recognize_request request_pb
  query_string_params = if query_string_params.any?
                          query_string_params.to_h { |p| p.split "=", 2 }
                        else
                          {}
                        end

  response = @client_stub.make_http_request(
    verb,
    uri:     uri,
    body:    body || "",
    params:  query_string_params,
    options: options
  )
  operation = ::Gapic::Rest::TransportOperation.new response
  result = ::Google::Cloud::Speech::V1::RecognizeResponse.decode_json response.body, ignore_unknown_fields: true

  yield result, operation if block_given?
  result
end

#universe_domainString

The effective universe domain

Returns:

  • (String)


51
52
53
# File 'lib/google/cloud/speech/v1/speech/rest/service_stub.rb', line 51

def universe_domain
  @client_stub.universe_domain
end