Merge branch 'master' of https://code.google.com/p/google-api-ruby-client
This commit is contained in:
commit
1121bb7fe6
|
@ -1,3 +1,7 @@
|
||||||
|
# 0.4.2
|
||||||
|
|
||||||
|
* Fixed incompatibility with Ruby 1.8.7
|
||||||
|
|
||||||
# 0.4.1
|
# 0.4.1
|
||||||
|
|
||||||
* Fixed ancestor checking issue when assigning Autoparse identifiers
|
* Fixed ancestor checking issue when assigning Autoparse identifiers
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = "google-api-client"
|
s.name = "google-api-client"
|
||||||
s.version = "0.4.1"
|
s.version = "0.4.2"
|
||||||
|
|
||||||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||||
s.authors = ["Bob Aman"]
|
s.authors = ["Bob Aman"]
|
||||||
s.date = "2012-02-10"
|
s.date = "2012-02-22"
|
||||||
s.description = "The Google API Ruby Client makes it trivial to discover and access supported\nAPIs.\n"
|
s.description = "The Google API Ruby Client makes it trivial to discover and access supported\nAPIs.\n"
|
||||||
s.email = "bobaman@google.com"
|
s.email = "bobaman@google.com"
|
||||||
s.executables = ["google-api"]
|
s.executables = ["google-api"]
|
||||||
|
|
|
@ -47,8 +47,6 @@ module Google
|
||||||
# <li><code>:oauth_1</code></li>
|
# <li><code>:oauth_1</code></li>
|
||||||
# <li><code>:oauth_2</code></li>
|
# <li><code>:oauth_2</code></li>
|
||||||
# </ul>
|
# </ul>
|
||||||
# @option options [String] :host ("www.googleapis.com")
|
|
||||||
# The API hostname used by the client. This rarely needs to be changed.
|
|
||||||
# @option options [String] :application_name
|
# @option options [String] :application_name
|
||||||
# The name of the application using the client.
|
# The name of the application using the client.
|
||||||
# @option options [String] :application_version
|
# @option options [String] :application_version
|
||||||
|
@ -57,6 +55,12 @@ module Google
|
||||||
# ("{app_name} google-api-ruby-client/{version} {os_name}/{os_version}")
|
# ("{app_name} google-api-ruby-client/{version} {os_name}/{os_version}")
|
||||||
# The user agent used by the client. Most developers will want to
|
# The user agent used by the client. Most developers will want to
|
||||||
# leave this value alone and use the `:application_name` option instead.
|
# leave this value alone and use the `:application_name` option instead.
|
||||||
|
# @option options [String] :host ("www.googleapis.com")
|
||||||
|
# The API hostname used by the client. This rarely needs to be changed.
|
||||||
|
# @option options [String] :port (443)
|
||||||
|
# The port number used by the client. This rarely needs to be changed.
|
||||||
|
# @option options [String] :discovery_path ("/discovery/v1")
|
||||||
|
# The discovery base path. This rarely needs to be changed.
|
||||||
def initialize(options={})
|
def initialize(options={})
|
||||||
# Normalize key to String to allow indifferent access.
|
# Normalize key to String to allow indifferent access.
|
||||||
options = options.inject({}) do |accu, (key, value)|
|
options = options.inject({}) do |accu, (key, value)|
|
||||||
|
@ -65,6 +69,9 @@ module Google
|
||||||
end
|
end
|
||||||
# Almost all API usage will have a host of 'www.googleapis.com'.
|
# Almost all API usage will have a host of 'www.googleapis.com'.
|
||||||
self.host = options["host"] || 'www.googleapis.com'
|
self.host = options["host"] || 'www.googleapis.com'
|
||||||
|
self.port = options["port"] || 443
|
||||||
|
self.discovery_path = options["discovery_path"] || '/discovery/v1'
|
||||||
|
|
||||||
# Most developers will want to leave this value alone and use the
|
# Most developers will want to leave this value alone and use the
|
||||||
# application_name option.
|
# application_name option.
|
||||||
application_string = (
|
application_string = (
|
||||||
|
@ -80,7 +87,7 @@ module Google
|
||||||
).strip
|
).strip
|
||||||
# The writer method understands a few Symbols and will generate useful
|
# The writer method understands a few Symbols and will generate useful
|
||||||
# default authentication mechanisms.
|
# default authentication mechanisms.
|
||||||
self.authorization = options["authorization"] || :oauth_2
|
self.authorization = options.key?("authorization") ? options["authorization"] : :oauth_2
|
||||||
self.key = options["key"]
|
self.key = options["key"]
|
||||||
self.user_ip = options["user_ip"]
|
self.user_ip = options["user_ip"]
|
||||||
@discovery_uris = {}
|
@discovery_uris = {}
|
||||||
|
@ -160,13 +167,6 @@ module Google
|
||||||
# @return [String] The user's IP address.
|
# @return [String] The user's IP address.
|
||||||
attr_accessor :user_ip
|
attr_accessor :user_ip
|
||||||
|
|
||||||
##
|
|
||||||
# The API hostname used by the client.
|
|
||||||
#
|
|
||||||
# @return [String]
|
|
||||||
# The API hostname. Should almost always be 'www.googleapis.com'.
|
|
||||||
attr_accessor :host
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# The user agent used by the client.
|
# The user agent used by the client.
|
||||||
#
|
#
|
||||||
|
@ -174,15 +174,58 @@ module Google
|
||||||
# The user agent string used in the User-Agent header.
|
# The user agent string used in the User-Agent header.
|
||||||
attr_accessor :user_agent
|
attr_accessor :user_agent
|
||||||
|
|
||||||
|
##
|
||||||
|
# The API hostname used by the client.
|
||||||
|
#
|
||||||
|
# @return [String]
|
||||||
|
# The API hostname. Should almost always be 'www.googleapis.com'.
|
||||||
|
attr_accessor :host
|
||||||
|
|
||||||
|
##
|
||||||
|
# The port number used by the client.
|
||||||
|
#
|
||||||
|
# @return [String]
|
||||||
|
# The port number. Should almost always be 443.
|
||||||
|
attr_accessor :port
|
||||||
|
|
||||||
|
##
|
||||||
|
# The base path used by the client for discovery.
|
||||||
|
#
|
||||||
|
# @return [String]
|
||||||
|
# The base path. Should almost always be '/discovery/v1'.
|
||||||
|
attr_accessor :discovery_path
|
||||||
|
|
||||||
|
##
|
||||||
|
# Resolves a URI template against the client's configured base.
|
||||||
|
#
|
||||||
|
# @param [String, Addressable::URI, Addressable::Template] template
|
||||||
|
# The template to resolve.
|
||||||
|
# @param [Hash] mapping The mapping that corresponds to the template.
|
||||||
|
# @return [Addressable::URI] The expanded URI.
|
||||||
|
def resolve_uri(template, mapping={})
|
||||||
|
@base_uri ||= Addressable::URI.new(
|
||||||
|
:scheme => 'https',
|
||||||
|
:host => self.host,
|
||||||
|
:port => self.port
|
||||||
|
).normalize
|
||||||
|
template = if template.kind_of?(Addressable::Template)
|
||||||
|
template.pattern
|
||||||
|
elsif template.respond_to?(:to_str)
|
||||||
|
template.to_str
|
||||||
|
else
|
||||||
|
raise TypeError,
|
||||||
|
"Expected String, Addressable::URI, or Addressable::Template, " +
|
||||||
|
"got #{template.class}."
|
||||||
|
end
|
||||||
|
return Addressable::Template.new(@base_uri + template).expand(mapping)
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Returns the URI for the directory document.
|
# Returns the URI for the directory document.
|
||||||
#
|
#
|
||||||
# @return [Addressable::URI] The URI of the directory document.
|
# @return [Addressable::URI] The URI of the directory document.
|
||||||
def directory_uri
|
def directory_uri
|
||||||
template = Addressable::Template.new(
|
return resolve_uri(self.discovery_path + '/apis')
|
||||||
"https://{host}/discovery/v1/apis"
|
|
||||||
)
|
|
||||||
return template.expand({"host" => self.host})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -207,17 +250,13 @@ module Google
|
||||||
def discovery_uri(api, version=nil)
|
def discovery_uri(api, version=nil)
|
||||||
api = api.to_s
|
api = api.to_s
|
||||||
version = version || 'v1'
|
version = version || 'v1'
|
||||||
return @discovery_uris["#{api}:#{version}"] ||= (begin
|
return @discovery_uris["#{api}:#{version}"] ||= (
|
||||||
template = Addressable::Template.new(
|
resolve_uri(
|
||||||
"https://{host}/discovery/v1/apis/" +
|
self.discovery_path + '/apis/{api}/{version}/rest',
|
||||||
"{api}/{version}/rest"
|
'api' => api,
|
||||||
|
'version' => version
|
||||||
|
)
|
||||||
)
|
)
|
||||||
template.expand({
|
|
||||||
"host" => self.host,
|
|
||||||
"api" => api,
|
|
||||||
"version" => version
|
|
||||||
})
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -596,7 +635,7 @@ module Google
|
||||||
unless headers.kind_of?(Enumerable)
|
unless headers.kind_of?(Enumerable)
|
||||||
# We need to use some Enumerable methods, relying on the presence of
|
# We need to use some Enumerable methods, relying on the presence of
|
||||||
# the #each method.
|
# the #each method.
|
||||||
class <<headers
|
class << headers
|
||||||
include Enumerable
|
include Enumerable
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,7 +43,7 @@ module Google
|
||||||
def initialize(document_base, discovery_document)
|
def initialize(document_base, discovery_document)
|
||||||
@document_base = Addressable::URI.parse(document_base)
|
@document_base = Addressable::URI.parse(document_base)
|
||||||
@discovery_document = discovery_document
|
@discovery_document = discovery_document
|
||||||
metaclass = (class <<self; self; end)
|
metaclass = (class << self; self; end)
|
||||||
self.discovered_resources.each do |resource|
|
self.discovered_resources.each do |resource|
|
||||||
method_name = Google::INFLECTOR.underscore(resource.name).to_sym
|
method_name = Google::INFLECTOR.underscore(resource.name).to_sym
|
||||||
if !self.respond_to?(method_name)
|
if !self.respond_to?(method_name)
|
||||||
|
|
|
@ -47,8 +47,13 @@ module Google
|
||||||
# and excess object creation, but this hopefully shouldn't be an
|
# and excess object creation, but this hopefully shouldn't be an
|
||||||
# issue since it should only be called only once per schema per
|
# issue since it should only be called only once per schema per
|
||||||
# process.
|
# process.
|
||||||
if data.kind_of?(Hash) && data['$ref']
|
if data.kind_of?(Hash) &&
|
||||||
reference = data['$ref']
|
data['$ref'] && !data['$ref'].kind_of?(Hash)
|
||||||
|
if data['$ref'].respond_to?(:to_str)
|
||||||
|
reference = data['$ref'].to_str
|
||||||
|
else
|
||||||
|
raise TypeError, "Expected String, got #{data['$ref'].class}"
|
||||||
|
end
|
||||||
reference = '#' + reference if reference[0..0] != '#'
|
reference = '#' + reference if reference[0..0] != '#'
|
||||||
data.merge({
|
data.merge({
|
||||||
'$ref' => reference
|
'$ref' => reference
|
||||||
|
@ -74,22 +79,26 @@ module Google
|
||||||
Google::INFLECTOR.camelize(api.name)
|
Google::INFLECTOR.camelize(api.name)
|
||||||
api_version_string =
|
api_version_string =
|
||||||
Google::INFLECTOR.camelize(api.version).gsub('.', '_')
|
Google::INFLECTOR.camelize(api.version).gsub('.', '_')
|
||||||
if Google::APIClient::Schema.const_defined?(api_name_string, false)
|
# This is for compatibility with Ruby 1.8.7.
|
||||||
|
# TODO(bobaman) Remove this when we eventually stop supporting 1.8.7.
|
||||||
|
args = []
|
||||||
|
args << false if Class.method(:const_defined?).arity != 1
|
||||||
|
if Google::APIClient::Schema.const_defined?(api_name_string, *args)
|
||||||
api_name = Google::APIClient::Schema.const_get(
|
api_name = Google::APIClient::Schema.const_get(
|
||||||
api_name_string, false
|
api_name_string, *args
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
api_name = Google::APIClient::Schema.const_set(
|
api_name = Google::APIClient::Schema.const_set(
|
||||||
api_name_string, Module.new
|
api_name_string, Module.new
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
if api_name.const_defined?(api_version_string, false)
|
if api_name.const_defined?(api_version_string, *args)
|
||||||
api_version = api_name.const_get(api_version_string, false)
|
api_version = api_name.const_get(api_version_string, *args)
|
||||||
else
|
else
|
||||||
api_version = api_name.const_set(api_version_string, Module.new)
|
api_version = api_name.const_set(api_version_string, Module.new)
|
||||||
end
|
end
|
||||||
if api_version.const_defined?(schema_name, false)
|
if api_version.const_defined?(schema_name, *args)
|
||||||
schema_class = api_version.const_get(schema_name, false)
|
schema_class = api_version.const_get(schema_name, *args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,8 @@
|
||||||
module Google
|
module Google
|
||||||
class APIClient
|
class APIClient
|
||||||
module ENV
|
module ENV
|
||||||
OS_VERSION = if RUBY_PLATFORM =~ /mswin|win32|mingw|bccwin|cygwin/
|
OS_VERSION = begin
|
||||||
|
if RUBY_PLATFORM =~ /mswin|win32|mingw|bccwin|cygwin/
|
||||||
# TODO(bobaman)
|
# TODO(bobaman)
|
||||||
# Confirm that all of these Windows environments actually have access
|
# Confirm that all of these Windows environments actually have access
|
||||||
# to the `ver` command.
|
# to the `ver` command.
|
||||||
|
@ -26,6 +27,9 @@ module Google
|
||||||
else
|
else
|
||||||
`uname -sr`.sub(' ', '/')
|
`uname -sr`.sub(' ', '/')
|
||||||
end
|
end
|
||||||
|
rescue Exception
|
||||||
|
RUBY_PLATFORM
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,7 +22,7 @@ if !defined?(::Google::APIClient::VERSION)
|
||||||
module VERSION
|
module VERSION
|
||||||
MAJOR = 0
|
MAJOR = 0
|
||||||
MINOR = 4
|
MINOR = 4
|
||||||
TINY = 1
|
TINY = 2
|
||||||
|
|
||||||
STRING = [MAJOR, MINOR, TINY].join('.')
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue