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

Add GAX client_config to service factory #848

Merged
merged 1 commit into from
Sep 29, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion google-cloud-language/acceptance/language_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
require "google/cloud/language"

# Create shared language object so we don't create new for each test
$language = Google::Cloud.language retries: 10
$language = Google::Cloud.language

require "google/cloud/storage"

Expand Down
20 changes: 11 additions & 9 deletions google-cloud-language/lib/google-cloud-language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ module Cloud
# The default scope is:
#
# * `"https://www.googleapis.com/auth/cloud-platform"`
# @param [Integer] retries This option is not currently supported.
# @param [Integer] timeout Default timeout to use in requests. Optional.
# @param [Hash] client_config A hash of values to override the default
# behavior of the API client. See Google::Gax::CallSettings. Optional.
#
# @return [Google::Cloud::Language::Project]
#
Expand All @@ -60,10 +61,10 @@ module Cloud
# platform_scope = "https://www.googleapis.com/auth/cloud-platform"
# language = gcloud.language scope: platform_scope
#
def language scope: nil, retries: nil, timeout: nil
Google::Cloud.language @project, @keyfile, scope: scope,
retries: (retries || @retries),
timeout: (timeout || @timeout)
def language scope: nil, timeout: nil, client_config: nil
Google::Cloud.language @project, @keyfile,
scope: scope, timeout: (timeout || @timeout),
client_config: client_config
end

##
Expand All @@ -85,8 +86,9 @@ def language scope: nil, retries: nil, timeout: nil
# The default scope is:
#
# * `"https://www.googleapis.com/auth/cloud-platform"`
# @param [Integer] retries This option is not currently supported.
# @param [Integer] timeout Default timeout to use in requests. Optional.
# @param [Hash] client_config A hash of values to override the default
# behavior of the API client. See Google::Gax::CallSettings. Optional.
#
# @return [Google::Cloud::Language::Project]
#
Expand All @@ -99,8 +101,8 @@ def language scope: nil, retries: nil, timeout: nil
# document = language.document content
# annotation = document.annotate
#
def self.language project = nil, keyfile = nil, scope: nil, retries: nil,
timeout: nil
def self.language project = nil, keyfile = nil, scope: nil, timeout: nil,
client_config: nil
require "google/cloud/language"
project ||= Google::Cloud::Language::Project.default_project
if keyfile.nil?
Expand All @@ -111,7 +113,7 @@ def self.language project = nil, keyfile = nil, scope: nil, retries: nil,
end
Google::Cloud::Language::Project.new(
Google::Cloud::Language::Service.new(
project, credentials, retries: retries, timeout: timeout))
project, credentials, timeout: timeout, client_config: client_config))

This comment was marked as spam.

end
end
end
20 changes: 10 additions & 10 deletions google-cloud-language/lib/google/cloud/language/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ module Language
# @private Represents the gRPC Language service, including all the API
# methods.
class Service
attr_accessor :project, :credentials, :host, :retries, :timeout
attr_accessor :project, :credentials, :host, :client_config, :timeout

##
# Creates a new Service instance.
def initialize project, credentials, host: nil, retries: nil,
def initialize project, credentials, host: nil, client_config: nil,
timeout: nil
@project = project
@credentials = credentials
@host = host || V1beta1::LanguageServiceApi::SERVICE_ADDRESS
@retries = retries
@client_config = client_config || {}
@timeout = timeout
end

Expand All @@ -51,13 +51,13 @@ def chan_creds

def service
return mocked_service if mocked_service
@service ||= \
V1beta1::LanguageServiceApi.new(
service_path: host,
channel: channel,
timeout: timeout,
app_name: "google-cloud-language",
app_version: Google::Cloud::Language::VERSION)
@service ||= V1beta1::LanguageServiceApi.new(
service_path: host,
channel: channel,
timeout: timeout,
client_config: client_config,
app_name: "google-cloud-language",
app_version: Google::Cloud::Language::VERSION)
end
attr_accessor :mocked_service

Expand Down
18 changes: 9 additions & 9 deletions google-cloud-language/test/google/cloud/language_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
describe "#language" do
it "calls out to Google::Cloud.language" do
gcloud = Google::Cloud.new
stubbed_language = ->(project, keyfile, scope: nil, retries: nil, timeout: nil) {
stubbed_language = ->(project, keyfile, scope: nil, timeout: nil, client_config: nil) {
project.must_equal nil
keyfile.must_equal nil
scope.must_be :nil?
retries.must_be :nil?
timeout.must_be :nil?
client_config.must_be :nil?
"language-project-object-empty"
}
Google::Cloud.stub :language, stubbed_language do
Expand All @@ -34,12 +34,12 @@

it "passes project and keyfile to Google::Cloud.language" do
gcloud = Google::Cloud.new "project-id", "keyfile-path"
stubbed_language = ->(project, keyfile, scope: nil, retries: nil, timeout: nil) {
stubbed_language = ->(project, keyfile, scope: nil, timeout: nil, client_config: nil) {
project.must_equal "project-id"
keyfile.must_equal "keyfile-path"
scope.must_be :nil?
retries.must_be :nil?
timeout.must_be :nil?
client_config.must_be :nil?
"language-project-object"
}
Google::Cloud.stub :language, stubbed_language do
Expand All @@ -50,16 +50,16 @@

it "passes project and keyfile and options to Google::Cloud.language" do
gcloud = Google::Cloud.new "project-id", "keyfile-path"
stubbed_language = ->(project, keyfile, scope: nil, retries: nil, timeout: nil) {
stubbed_language = ->(project, keyfile, scope: nil, timeout: nil, client_config: nil) {
project.must_equal "project-id"
keyfile.must_equal "keyfile-path"
scope.must_equal "http://example.com/scope"
retries.must_equal 5
timeout.must_equal 60
client_config.must_equal({ "gax" => "options" })
"language-project-object-scoped"
}
Google::Cloud.stub :language, stubbed_language do
project = gcloud.language scope: "http://example.com/scope", retries: 5, timeout: 60
project = gcloud.language scope: "http://example.com/scope", timeout: 60, client_config: { "gax" => "options" }
project.must_equal "language-project-object-scoped"
end
end
Expand Down Expand Up @@ -90,11 +90,11 @@
scope.must_equal nil
"language-credentials"
}
stubbed_service = ->(project, credentials, retries: nil, timeout: nil) {
stubbed_service = ->(project, credentials, timeout: nil, client_config: nil) {
project.must_equal "project-id"
credentials.must_equal "language-credentials"
retries.must_equal nil
timeout.must_equal nil
client_config.must_equal nil
OpenStruct.new project: project
}

Expand Down