This commit is contained in:
Bob Aman 2012-02-10 17:17:42 +03:00
commit 6c0359720c
5 changed files with 14 additions and 16 deletions

View File

@ -44,7 +44,7 @@ module Google
@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.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)
metaclass.send(:define_method, method_name) { resource } metaclass.send(:define_method, method_name) { resource }
@ -164,7 +164,7 @@ module Google
# The new base URI to use for the service. # The new base URI to use for the service.
def method_base=(new_method_base) def method_base=(new_method_base)
@method_base = Addressable::URI.parse(new_method_base) @method_base = Addressable::URI.parse(new_method_base)
self.resources.each do |resource| self.discovered_resources.each do |resource|
resource.method_base = @method_base resource.method_base = @method_base
end end
self.methods.each do |method| self.methods.each do |method|
@ -207,7 +207,7 @@ module Google
# API. # API.
# #
# @return [Array] A list of {Google::APIClient::Resource} objects. # @return [Array] A list of {Google::APIClient::Resource} objects.
def resources def discovered_resources
return @resources ||= ( return @resources ||= (
(@discovery_document['resources'] || []).inject([]) do |accu, (k, v)| (@discovery_document['resources'] || []).inject([]) do |accu, (k, v)|
accu << Google::APIClient::Resource.new( accu << Google::APIClient::Resource.new(
@ -252,7 +252,7 @@ module Google
self.methods.each do |method| self.methods.each do |method|
methods_hash[method.id] = method methods_hash[method.id] = method
end end
self.resources.each do |resource| self.discovered_resources.each do |resource|
methods_hash.merge!(resource.to_h) methods_hash.merge!(resource.to_h)
end end
methods_hash methods_hash

View File

@ -42,7 +42,7 @@ module Google
@name = resource_name @name = resource_name
@discovery_document = discovery_document @discovery_document = discovery_document
metaclass = (class <<self; self; end) metaclass = (class <<self; self; end)
self.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)
metaclass.send(:define_method, method_name) { resource } metaclass.send(:define_method, method_name) { resource }
@ -82,7 +82,7 @@ module Google
# The new base URI to use for the resource. # The new base URI to use for the resource.
def method_base=(new_method_base) def method_base=(new_method_base)
@method_base = Addressable::URI.parse(new_method_base) @method_base = Addressable::URI.parse(new_method_base)
self.resources.each do |resource| self.discovered_resources.each do |resource|
resource.method_base = @method_base resource.method_base = @method_base
end end
self.methods.each do |method| self.methods.each do |method|
@ -94,7 +94,7 @@ module Google
# A list of sub-resources available on this resource. # A list of sub-resources available on this resource.
# #
# @return [Array] A list of {Google::APIClient::Resource} objects. # @return [Array] A list of {Google::APIClient::Resource} objects.
def resources def discovered_resources
return @resources ||= ( return @resources ||= (
(@discovery_document['resources'] || []).inject([]) do |accu, (k, v)| (@discovery_document['resources'] || []).inject([]) do |accu, (k, v)|
accu << Google::APIClient::Resource.new( accu << Google::APIClient::Resource.new(
@ -129,7 +129,7 @@ module Google
self.methods.each do |method| self.methods.each do |method|
methods_hash[method.id] = method methods_hash[method.id] = method
end end
self.resources.each do |resource| self.discovered_resources.each do |resource|
methods_hash.merge!(resource.to_h) methods_hash.merge!(resource.to_h)
end end
methods_hash methods_hash

View File

@ -74,20 +74,20 @@ 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) if Google::APIClient::Schema.const_defined?(api_name_string, false)
api_name = Google::APIClient::Schema.const_get(api_name_string) api_name = Google::APIClient::Schema.const_get(api_name_string, false)
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) if api_name.const_defined?(api_version_string, false)
api_version = api_name.const_get(api_version_string) api_version = api_name.const_get(api_version_string, false)
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) if api_version.const_defined?(schema_name, false)
schema_class = api_version.const_get(schema_name) schema_class = api_version.const_get(schema_name, false)
end end
end end

View File

@ -24,7 +24,6 @@ require 'signet/oauth_1/client'
require 'google/api_client' require 'google/api_client'
require 'google/api_client/version' require 'google/api_client/version'
require 'google/api_client/parsers/json_parser'
describe Google::APIClient do describe Google::APIClient do
before do before do

View File

@ -23,7 +23,6 @@ require 'signet/oauth_1/client'
require 'google/api_client' require 'google/api_client'
require 'google/api_client/version' require 'google/api_client/version'
require 'google/api_client/parsers/json_parser'
shared_examples_for 'configurable user agent' do shared_examples_for 'configurable user agent' do
it 'should allow the user agent to be modified' do it 'should allow the user agent to be modified' do