Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch Client to positional args #155

Merged
merged 5 commits into from May 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -13,7 +13,7 @@
# @example
<%= indent method.code_example, "# " %>
#
<%= render partial: "service/client/method/def/signature", locals: { method: method } -%>
def <%= method.name %> request, options = nil, &block
<%= indent render(partial: "service/client/method/def/request", locals: { method: method }), 2 %>

<%= indent render(partial: "service/client/method/def/options_defaults", locals: { method: method }), 2 %>
Expand Down
@@ -1,10 +1,4 @@
<%- assert_locals method -%>
if request.nil? && request_fields.empty?
raise ArgumentError, "request must be provided"
end
if !request.nil? && !request_fields.empty?
raise ArgumentError, "cannot pass both request object and named arguments"
end
raise ArgumentError, "request must be provided" if request.nil?

request ||= request_fields
request = Google::Gax::Protobuf.coerce request, to: <%= method.request_type %>

This file was deleted.

@@ -1,25 +1,14 @@
<%- assert_locals method -%>
# @overload <%= method.name %>(request, options: nil)
# @param request [<%= method.request_type %> | Hash]
# @param request [<%= method.request_type %> | Hash]
<%- if method.doc_description -%>
<%= indent method.doc_description, "# " %>
<%= indent method.doc_description, "# " %>
<%- end -%>
# @param options [Google::Gax::ApiCall::Options, Hash]
# Overrides the default settings for this call, e.g, timeout, retries, etc.
#
<%- arg_list = method.arguments.map { |arg| "#{arg.name}: nil"}.join ", " -%>
# @overload <%= method.name %>(<%= arg_list %>, options: nil)
# When using a hash, the following fields are supported:
#
<%- method.arguments.each do |arg| -%>
# @param <%= arg.name %> [<%= arg.doc_types %>]
<%- if arg.doc_description -%>
# * `<%= arg.name %>` (`<%= arg.doc_types %>`)<%- if arg.doc_description -%>:
quartzmo marked this conversation as resolved.
Show resolved Hide resolved
<%= indent arg.doc_description, "# " %>
<%- end -%>
<%- end -%>
# @param options [Google::Gax::ApiCall::Options, Hash]
# Overrides the default settings for this call, e.g, timeout, retries, etc.
<%- if method.arguments.find { |arg| arg.name == "options" } -%>
#
# If you want to provide a {<%= method.request_type %>#options}
# value you will need to pass all attributes in a Hash instead of using
# named arguments.
<%- end -%>
<%- end -%># @param options [Google::Gax::ApiCall::Options, Hash]
# Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
Expand Up @@ -2,4 +2,4 @@
# @param request [Google::Gax::StreamInput, Enumerable<<%= method.request_type %> | Hash>]
# An enumerable of {<%= method.request_type %>} instances.
# @param options [Google::Gax::ApiCall::Options, Hash]
# Overrides the default settings for this call, e.g, timeout, retries, etc.
# Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
Expand Up @@ -108,19 +108,17 @@ def initialize
##
# This method simply echos the request. This method is showcases unary rpcs.
#
# @overload echo(request, options: nil)
# @param request [Google::Showcase::V1alpha3::EchoRequest | Hash]
# This method simply echos the request. This method is showcases unary rpcs.
# @param options [Google::Gax::ApiCall::Options, Hash]
# Overrides the default settings for this call, e.g, timeout, retries, etc.
#
# @overload echo(content: nil, error: nil, options: nil)
# @param content [String]
# @param request [Google::Showcase::V1alpha3::EchoRequest | Hash]
# This method simply echos the request. This method is showcases unary rpcs.
#
# When using a hash, the following fields are supported:
#
# * `content` (`String`):
# The content to be echoed by the server.
# @param error [Google::Rpc::Status | Hash]
# * `error` (`Google::Rpc::Status | Hash`):
# The error to be thrown by the server.
# @param options [Google::Gax::ApiCall::Options, Hash]
# Overrides the default settings for this call, e.g, timeout, retries, etc.
# @param options [Google::Gax::ApiCall::Options, Hash]
# Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
#
# @yield [response, operation] Access the result along with the RPC operation
# @yieldparam response [Google::Showcase::V1alpha3::EchoResponse]
Expand All @@ -133,13 +131,9 @@ def initialize
# @example
# TODO
#
def echo request = nil, options: nil, **request_fields, &block
raise ArgumentError, "request must be provided" if request.nil? && request_fields.empty?
if !request.nil? && !request_fields.empty?
raise ArgumentError, "cannot pass both request object and named arguments"
end
def echo request, options = nil, &block
raise ArgumentError, "request must be provided" if request.nil?

request ||= request_fields
request = Google::Gax::Protobuf.coerce request, to: Google::Showcase::V1alpha3::EchoRequest

# Converts hash and nil to an options object
Expand Down Expand Up @@ -172,20 +166,18 @@ def echo request = nil, options: nil, **request_fields, &block
# This method split the given content into words and will pass each word back
# through the stream. This method showcases server-side streaming rpcs.
#
# @overload expand(request, options: nil)
# @param request [Google::Showcase::V1alpha3::ExpandRequest | Hash]
# This method split the given content into words and will pass each word back
# through the stream. This method showcases server-side streaming rpcs.
# @param options [Google::Gax::ApiCall::Options, Hash]
# Overrides the default settings for this call, e.g, timeout, retries, etc.
# @param request [Google::Showcase::V1alpha3::ExpandRequest | Hash]
# This method split the given content into words and will pass each word back
# through the stream. This method showcases server-side streaming rpcs.
#
# @overload expand(content: nil, error: nil, options: nil)
# @param content [String]
# When using a hash, the following fields are supported:
#
# * `content` (`String`):
# The content that will be split into words and returned on the stream.
# @param error [Google::Rpc::Status | Hash]
# * `error` (`Google::Rpc::Status | Hash`):
# The error that is thrown after all words are sent on the stream.
# @param options [Google::Gax::ApiCall::Options, Hash]
# Overrides the default settings for this call, e.g, timeout, retries, etc.
# @param options [Google::Gax::ApiCall::Options, Hash]
# Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
#
# @yield [response, operation] Access the result along with the RPC operation
# @yieldparam response [Enumerable<Google::Showcase::V1alpha3::EchoResponse>]
Expand All @@ -198,13 +190,9 @@ def echo request = nil, options: nil, **request_fields, &block
# @example
# TODO
#
def expand request = nil, options: nil, **request_fields, &block
raise ArgumentError, "request must be provided" if request.nil? && request_fields.empty?
if !request.nil? && !request_fields.empty?
raise ArgumentError, "cannot pass both request object and named arguments"
end
def expand request, options = nil, &block
raise ArgumentError, "request must be provided" if request.nil?

request ||= request_fields
request = Google::Gax::Protobuf.coerce request, to: Google::Showcase::V1alpha3::ExpandRequest

# Converts hash and nil to an options object
Expand Down Expand Up @@ -241,7 +229,7 @@ def expand request = nil, options: nil, **request_fields, &block
# @param request [Google::Gax::StreamInput, Enumerable<Google::Showcase::V1alpha3::EchoRequest | Hash>]
# An enumerable of {Google::Showcase::V1alpha3::EchoRequest} instances.
# @param options [Google::Gax::ApiCall::Options, Hash]
# Overrides the default settings for this call, e.g, timeout, retries, etc.
# Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
#
# @yield [response, operation] Access the result along with the RPC operation
# @yieldparam response [Google::Showcase::V1alpha3::EchoResponse]
Expand All @@ -254,7 +242,7 @@ def expand request = nil, options: nil, **request_fields, &block
# @example
# TODO
#
def collect request, options: nil, &block
def collect request, options = nil, &block
unless request.is_a? Enumerable
if request.respond_to? :to_enum
request = request.to_enum
Expand Down Expand Up @@ -301,7 +289,7 @@ def collect request, options: nil, &block
# @param request [Google::Gax::StreamInput, Enumerable<Google::Showcase::V1alpha3::EchoRequest | Hash>]
# An enumerable of {Google::Showcase::V1alpha3::EchoRequest} instances.
# @param options [Google::Gax::ApiCall::Options, Hash]
# Overrides the default settings for this call, e.g, timeout, retries, etc.
# Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
#
# @yield [response, operation] Access the result along with the RPC operation
# @yieldparam response [Enumerable<Google::Showcase::V1alpha3::EchoResponse>]
Expand All @@ -314,7 +302,7 @@ def collect request, options: nil, &block
# @example
# TODO
#
def chat request, options: nil, &block
def chat request, options = nil, &block
unless request.is_a? Enumerable
if request.respond_to? :to_enum
request = request.to_enum
Expand Down Expand Up @@ -357,22 +345,20 @@ def chat request, options: nil, &block
# This is similar to the Expand method but instead of returning a stream of
# expanded words, this method returns a paged list of expanded words.
#
# @overload paged_expand(request, options: nil)
# @param request [Google::Showcase::V1alpha3::PagedExpandRequest | Hash]
# This is similar to the Expand method but instead of returning a stream of
# expanded words, this method returns a paged list of expanded words.
# @param options [Google::Gax::ApiCall::Options, Hash]
# Overrides the default settings for this call, e.g, timeout, retries, etc.
# @param request [Google::Showcase::V1alpha3::PagedExpandRequest | Hash]
# This is similar to the Expand method but instead of returning a stream of
# expanded words, this method returns a paged list of expanded words.
#
# @overload paged_expand(content: nil, page_size: nil, page_token: nil, options: nil)
# @param content [String]
# When using a hash, the following fields are supported:
#
# * `content` (`String`):
# The string to expand.
# @param page_size [Integer]
# * `page_size` (`Integer`):
# The amount of words to returned in each page.
# @param page_token [String]
# * `page_token` (`String`):
# The position of the page to be returned.
# @param options [Google::Gax::ApiCall::Options, Hash]
# Overrides the default settings for this call, e.g, timeout, retries, etc.
# @param options [Google::Gax::ApiCall::Options, Hash]
# Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
#
# @yield [response, operation] Access the result along with the RPC operation
# @yieldparam response [Google::Gax::PagedEnumerable<Google::Showcase::V1alpha3::EchoResponse>]
Expand All @@ -385,13 +371,9 @@ def chat request, options: nil, &block
# @example
# TODO
#
def paged_expand request = nil, options: nil, **request_fields, &block
raise ArgumentError, "request must be provided" if request.nil? && request_fields.empty?
if !request.nil? && !request_fields.empty?
raise ArgumentError, "cannot pass both request object and named arguments"
end
def paged_expand request, options = nil, &block
raise ArgumentError, "request must be provided" if request.nil?

request ||= request_fields
request = Google::Gax::Protobuf.coerce request, to: Google::Showcase::V1alpha3::PagedExpandRequest

# Converts hash and nil to an options object
Expand Down Expand Up @@ -425,25 +407,23 @@ def paged_expand request = nil, options: nil, **request_fields, &block
# This method will wait the requested amount of and then return.
# This method showcases how a client handles a request timing out.
#
# @overload wait(request, options: nil)
# @param request [Google::Showcase::V1alpha3::WaitRequest | Hash]
# This method will wait the requested amount of and then return.
# This method showcases how a client handles a request timing out.
# @param options [Google::Gax::ApiCall::Options, Hash]
# Overrides the default settings for this call, e.g, timeout, retries, etc.
# @param request [Google::Showcase::V1alpha3::WaitRequest | Hash]
# This method will wait the requested amount of and then return.
# This method showcases how a client handles a request timing out.
#
# @overload wait(end_time: nil, ttl: nil, error: nil, success: nil, options: nil)
# @param end_time [Google::Protobuf::Timestamp | Hash]
# When using a hash, the following fields are supported:
#
# * `end_time` (`Google::Protobuf::Timestamp | Hash`):
# The time that this operation will complete.
# @param ttl [Google::Protobuf::Duration | Hash]
# * `ttl` (`Google::Protobuf::Duration | Hash`):
# The duration of this operation.
# @param error [Google::Rpc::Status | Hash]
# * `error` (`Google::Rpc::Status | Hash`):
# The error that will be returned by the server. If this code is specified
# to be the OK rpc code, an empty response will be returned.
# @param success [Google::Showcase::V1alpha3::WaitResponse | Hash]
# * `success` (`Google::Showcase::V1alpha3::WaitResponse | Hash`):
# The response to be returned on operation completion.
# @param options [Google::Gax::ApiCall::Options, Hash]
# Overrides the default settings for this call, e.g, timeout, retries, etc.
# @param options [Google::Gax::ApiCall::Options, Hash]
# Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
#
# @yield [response, operation] Access the result along with the RPC operation
# @yieldparam response [Google::Gax::Operation]
Expand All @@ -456,13 +436,9 @@ def paged_expand request = nil, options: nil, **request_fields, &block
# @example
# TODO
#
def wait request = nil, options: nil, **request_fields, &block
raise ArgumentError, "request must be provided" if request.nil? && request_fields.empty?
if !request.nil? && !request_fields.empty?
raise ArgumentError, "cannot pass both request object and named arguments"
end
def wait request, options = nil, &block
raise ArgumentError, "request must be provided" if request.nil?

request ||= request_fields
request = Google::Gax::Protobuf.coerce request, to: Google::Showcase::V1alpha3::WaitRequest

# Converts hash and nil to an options object
Expand Down