diff --git a/lib/google/api_client.rb b/lib/google/api_client.rb
index 090dda26a..94285acb8 100644
--- a/lib/google/api_client.rb
+++ b/lib/google/api_client.rb
@@ -47,8 +47,8 @@ module Google
#
:oauth_1
# :oauth_2
#
- # @option options [String] :host ("www.googleapis.com")
- # The API hostname used by the client. This rarely needs to be changed.
+ # @option options [String] :baseURI ("https://www.googleapis.com/discovery/v1")
+ # The base API URI used by the client. This rarely needs to be changed.
# @option options [String] :application_name
# The name of the application using the client.
# @option options [String] :application_version
@@ -63,8 +63,9 @@ module Google
accu[key.to_s] = value
accu
end
- # Almost all API usage will have a host of 'www.googleapis.com'.
- self.host = options["host"] || 'www.googleapis.com'
+ # Almost all API usage will have this base URI
+ self.baseURI = options["baseURI"] || "https://www.googleapis.com/discovery/v1"
+
# Most developers will want to leave this value alone and use the
# application_name option.
application_string = (
@@ -80,7 +81,7 @@ module Google
).strip
# The writer method understands a few Symbols and will generate useful
# default authentication mechanisms.
- self.authorization = options["authorization"] || :oauth_2
+ self.authorization = options.key?("authorization") ? options["authorization"] : :oauth_2
self.key = options["key"]
self.user_ip = options["user_ip"]
@discovery_uris = {}
@@ -165,7 +166,7 @@ module Google
#
# @return [String]
# The API hostname. Should almost always be 'www.googleapis.com'.
- attr_accessor :host
+ attr_accessor :baseURI
##
# The user agent used by the client.
@@ -173,16 +174,17 @@ module Google
# @return [String]
# The user agent string used in the User-Agent header.
attr_accessor :user_agent
+
+ def relative_uri(path, expand={})
+ Addressable::Template.new(baseURI+path).expand(expand)
+ end
##
# Returns the URI for the directory document.
#
# @return [Addressable::URI] The URI of the directory document.
def directory_uri
- template = Addressable::Template.new(
- "https://{host}/discovery/v1/apis"
- )
- return template.expand({"host" => self.host})
+ relative_uri('/apis')
end
##
@@ -208,15 +210,7 @@ module Google
api = api.to_s
version = version || 'v1'
return @discovery_uris["#{api}:#{version}"] ||= (begin
- template = Addressable::Template.new(
- "https://{host}/discovery/v1/apis/" +
- "{api}/{version}/rest"
- )
- template.expand({
- "host" => self.host,
- "api" => api,
- "version" => version
- })
+ relative_uri("/apis/{api}/{version}/rest", 'api' => api, 'version' => version)
end)
end
@@ -596,7 +590,7 @@ module Google
unless headers.kind_of?(Enumerable)
# We need to use some Enumerable methods, relying on the presence of
# the #each method.
- class <