require 'addressable/uri'
-require 'google/inflection'
+require 'active_support/inflector'
require 'google/api_client/discovery/method'
##
# Creates a description of a particular version of a resource.
#
- # @param [Addressable::URI] base
+ # @param [Google::APIClient::API] api
+ # The API this resource belongs to.
+ # @param [Addressable::URI] method_base
# The base URI for the service.
# @param [String] resource_name
# The identifier for the resource.
- # @param [Hash] resource_description
+ # @param [Hash] discovery_document
# The section of the discovery document that applies to this resource.
#
# @return [Google::APIClient::Resource] The constructed resource object.
@discovery_document = discovery_document
metaclass = (class <<self; self; end)
self.discovered_resources.each do |resource|
- method_name = Google::INFLECTOR.underscore(resource.name).to_sym
+ method_name = ActiveSupport::Inflector.underscore(resource.name).to_sym
if !self.respond_to?(method_name)
metaclass.send(:define_method, method_name) { resource }
end
end
- self.methods.each do |method|
- method_name = Google::INFLECTOR.underscore(method.name).to_sym
+ self.discovered_methods.each do |method|
+ method_name = ActiveSupport::Inflector.underscore(method.name).to_sym
if !self.respond_to?(method_name)
metaclass.send(:define_method, method_name) { method }
end
end
end
+ # @return [String] unparsed discovery document for the resource
+ attr_reader :discovery_document
+
##
# Returns the identifier for the resource.
#
# @return [String] The resource identifier.
attr_reader :name
- ##
- # Returns the parsed section of the discovery document that applies to
- # this resource.
- #
- # @return [Hash] The resource description.
- attr_reader :description
-
##
# Returns the base URI for this resource.
#
# @return [Addressable::URI] The base URI that methods are joined to.
attr_reader :method_base
+ ##
+ # Returns a human-readable description of the resource.
+ #
+ # @return [Hash] The API description.
+ def description
+ return @discovery_document['description']
+ end
+
##
# Updates the hierarchy of resources and methods with the new base.
#
- # @param [Addressable::URI, #to_str, String] new_base
+ # @param [Addressable::URI, #to_str, String] new_method_base
# The new base URI to use for the resource.
def method_base=(new_method_base)
@method_base = Addressable::URI.parse(new_method_base)
self.discovered_resources.each do |resource|
resource.method_base = @method_base
end
- self.methods.each do |method|
+ self.discovered_methods.each do |method|
method.method_base = @method_base
end
end
#
# @return [Array] A list of {Google::APIClient::Resource} objects.
def discovered_resources
- return @resources ||= (
+ return @discovered_resources ||= (
(@discovery_document['resources'] || []).inject([]) do |accu, (k, v)|
accu << Google::APIClient::Resource.new(
@api, self.method_base, k, v
# A list of methods available on this resource.
#
# @return [Array] A list of {Google::APIClient::Method} objects.
- def methods
- return @methods ||= (
+ def discovered_methods
+ return @discovered_methods ||= (
(@discovery_document['methods'] || []).inject([]) do |accu, (k, v)|
accu << Google::APIClient::Method.new(@api, self.method_base, k, v)
accu
def to_h
return @hash ||= (begin
methods_hash = {}
- self.methods.each do |method|
+ self.discovered_methods.each do |method|
methods_hash[method.id] = method
end
self.discovered_resources.each do |resource|