Method: Gruf::Client#call

Defined in:
lib/gruf/client.rb

#call(request_method, params = {}, metadata = {}, opts = {}, &block) ⇒ Gruf::Response

Call the client’s method with given params

required for the given above call error type that was returned

Parameters:

  • request_method (String|Symbol)

    The method that is being requested on the service

  • params (Hash) (defaults to: {})

    (Optional) A hash of parameters that will be inserted into the gRPC request message that is

  • metadata (Hash) (defaults to: {})

    (Optional) A hash of metadata key/values that are transported with the client request

  • opts (Hash) (defaults to: {})

    (Optional) A hash of options to send to the gRPC request_response method

Returns:

Raises:

  • (Gruf::Client::Error|GRPC::BadStatus)

    If an error occurs, an exception will be raised according to the



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/gruf/client.rb', line 82

def call(request_method, params = {},  = {}, opts = {}, &block)
  request_method = request_method.to_sym
  req = if params.respond_to?(:to_proto) || streaming_request?(request_method)
          params
        else
          request_object(request_method, params)
        end
  md = ()
  call_sig = call_signature(request_method)

  unless call_sig
    raise NotImplementedError, "The method #{request_method} has not been implemented in this service."
  end

  resp, operation = execute(call_sig, req, md, opts, &block)

  raise @error_factory.from_exception(resp.result) unless resp.success?

  Gruf::Response.new(operation: operation, message: resp.result, execution_time: resp.time)
end