Respect discovered methods with colons in path
[arvados.git] / lib / google / api_client / discovery / method.rb
index 80c94a828b6eb20a2eca9055c5a9a411095ebfe3..3a06857c0e3d559f0e4e20813767d0c3dee639a8 100644 (file)
@@ -34,7 +34,7 @@ module Google
       #   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.
@@ -45,6 +45,9 @@ module Google
         @discovery_document = discovery_document
       end
 
+      # @return [String] unparsed discovery document for the method
+      attr_reader :discovery_document
+
       ##
       # Returns the API this method belongs to.
       #
@@ -57,13 +60,6 @@ module Google
       # @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.
       #
@@ -74,13 +70,21 @@ module Google
       ##
       # 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.
       #
@@ -104,7 +108,7 @@ module Google
       # @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
 
@@ -176,12 +180,14 @@ module Google
       ##
       # 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')
@@ -214,6 +220,7 @@ module Google
       ##
       # 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.
@@ -222,28 +229,14 @@ module Google
       #   The HTTP connection to use.
       #
       # @return [Array] The generated HTTP request.
-      def generate_request(parameters={}, body='', headers=[], options={})
-        options[:connection] ||= Faraday.default_connection
-        if body.respond_to?(:string)
-          body = body.string
-        elsif body.respond_to?(:to_str)
-          body = body.to_str
-        else
-          raise TypeError, "Expected String or StringIO, got #{body.class}."
-        end
+      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).normalize.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
 
 
@@ -302,6 +295,7 @@ module Google
       # 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.
       #