# The base URI for the service.
# @param [String] method_name
# The identifier for the method.
- # @param [Hash] method_description
+ # @param [Hash] discovery_document
# The section of the discovery document that applies to this method.
#
# @return [Google::APIClient::Method] The constructed method object.
@discovery_document = discovery_document
end
+ # @return [String] unparsed discovery document for the method
+ attr_reader :discovery_document
+
##
# Returns the API this method belongs to.
#
# @return [String] The method identifier.
attr_reader :name
- ##
- # Returns the parsed section of the discovery document that applies to
- # this method.
- #
- # @return [Hash] The method description.
- attr_reader :description
-
##
# Returns the base URI for the method.
#
##
# Updates the method 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 method.
def method_base=(new_method_base)
@method_base = Addressable::URI.parse(new_method_base)
@uri_template = nil
end
+ ##
+ # Returns a human-readable description of the method.
+ #
+ # @return [Hash] The API description.
+ def description
+ return @discovery_document['description']
+ end
+
##
# Returns the method ID.
#
# @return [Addressable::Template] The URI template.
def uri_template
return @uri_template ||= Addressable::Template.new(
- self.method_base.join(Addressable::URI.parse(@discovery_document['path']))
+ self.method_base.join(Addressable::URI.parse("./" + @discovery_document['path']))
)
end
##
# Expands the method's URI template using a parameter list.
#
+ # @api private
# @param [Hash, Array] parameters
# The parameter list to use.
#
# @return [Addressable::URI] The URI after expansion.
def generate_uri(parameters={})
parameters = self.normalize_parameters(parameters)
+
self.validate_parameters(parameters)
template_variables = self.uri_template.variables
upload_type = parameters.assoc('uploadType') || parameters.assoc('upload_type')
##
# Generates an HTTP request for this method.
#
+ # @api private
# @param [Hash, Array] parameters
# The parameters to send.
# @param [String, StringIO] body The body for the HTTP request.
# The HTTP connection to use.
#
# @return [Array] The generated HTTP request.
- def generate_request(parameters={}, body='', headers=[], options={})
- options[:connection] ||= Faraday.default_connection
+ def generate_request(parameters={}, body='', headers={}, options={})
if !headers.kind_of?(Array) && !headers.kind_of?(Hash)
raise TypeError, "Expected Hash or Array, got #{headers.class}."
end
- method = self.http_method
+ method = self.http_method.to_s.downcase.to_sym
uri = self.generate_uri(parameters)
- headers = headers.to_a if headers.kind_of?(Hash)
- return options[:connection].build_request(
- method.to_s.downcase.to_sym
- ) do |req|
- req.url(Addressable::URI.parse(uri).to_s)
- req.headers = Faraday::Utils::Headers.new(headers)
- req.body = body
- end
+ headers = Faraday::Utils::Headers.new(headers)
+ return [method, uri, headers, body]
end
# Verifies that the parameters are valid for this method. Raises an
# exception if validation fails.
#
+ # @api private
# @param [Hash, Array] parameters
# The parameters to verify.
#