googleapis / gax-ruby

Google API Extensions for Ruby
https://rubygems.org/gems/google-gax
BSD 3-Clause "New" or "Revised" License
20 stars 22 forks source link

GAPIC helper methods are inconvenient #125

Closed blowmage closed 5 years ago

blowmage commented 6 years ago

As discussed in #119, the GAPIC client helper methods are inconvenient and are being avoided in code examples. They could be better.

Take this Spanner GAPIC client example, the longest line is calling the session_path code example:

require "google/cloud/spanner/v1"

spanner_client = Google::Cloud::Spanner::V1.new

session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
sql = "SELECT * FROM users"

response = spanner_client.execute_sql(session, sql)
frankyn commented 6 years ago

@jbolinger +1, instance methods will help unblock sample code for Ruby.

blowmage commented 6 years ago

Here are some options for the code in the issue description:

First, the existing helper method can be called by calling .class on the client object. This would require no changes and works today.

require "google/cloud/spanner/v1"

spanner_client = Google::Cloud::Spanner::V1.new

session = spanner_client.class.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
sql = "SELECT * FROM users"

response = spanner_client.execute_sql(session, sql)

Another option is to add session_path as an instance method on the SpannerClient class.

require "google/cloud/spanner/v1"

spanner_client = Google::Cloud::Spanner::V1.new

session = spanner_client.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
sql = "SELECT * FROM users"

response = spanner_client.execute_sql(session, sql)
jbolinger commented 5 years ago

This has been moved here: https://github.com/googleapis/gapic-generator-ruby/issues/6https://github.com/googleapis/gapic-generator-ruby/issues/6