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 < 0
- uri.query_values = (uri.query_values || []) + query_parameters
+ # encode all non-template parameters
+ params = ""
+ unless query_parameters.empty?
+ params = "?" + Addressable::URI.form_encode(query_parameters)
end
# Normalization is necessary because of undesirable percent-escaping
# during URI template expansion
- return uri.normalize
+ return uri.normalize + params
end
##
diff --git a/lib/google/api_client/discovery/schema.rb b/lib/google/api_client/discovery/schema.rb
index f3499ebdc..2b4d59833 100644
--- a/lib/google/api_client/discovery/schema.rb
+++ b/lib/google/api_client/discovery/schema.rb
@@ -47,7 +47,7 @@ module Google
# and excess object creation, but this hopefully shouldn't be an
# issue since it should only be called only once per schema per
# process.
- if data.kind_of?(Hash) && data['$ref']
+ if data.kind_of?(Hash) && data['$ref'].is_a?(String)
reference = data['$ref']
reference = '#' + reference if reference[0..0] != '#'
data.merge({
diff --git a/lib/google/api_client/environment.rb b/lib/google/api_client/environment.rb
index e5abe9334..9faa28f7d 100644
--- a/lib/google/api_client/environment.rb
+++ b/lib/google/api_client/environment.rb
@@ -16,15 +16,19 @@
module Google
class APIClient
module ENV
- OS_VERSION = if RUBY_PLATFORM =~ /mswin|win32|mingw|bccwin|cygwin/
- # TODO(bobaman)
- # Confirm that all of these Windows environments actually have access
- # to the `ver` command.
- `ver`.sub(/\s*\[Version\s*/, '/').sub(']', '').strip
- elsif RUBY_PLATFORM =~ /darwin/i
- "Mac OS X/#{`sw_vers -productVersion`}"
- else
- `uname -sr`.sub(' ', '/')
+ OS_VERSION = begin
+ if RUBY_PLATFORM =~ /mswin|win32|mingw|bccwin|cygwin/
+ # TODO(bobaman)
+ # Confirm that all of these Windows environments actually have access
+ # to the `ver` command.
+ `ver`.sub(/\s*\[Version\s*/, '/').sub(']', '').strip
+ elsif RUBY_PLATFORM =~ /darwin/i
+ "Mac OS X/#{`sw_vers -productVersion`}"
+ else
+ `uname -sr`.sub(' ', '/')
+ end
+ rescue Exception
+ RUBY_PLATFORM
end
end
end