Added task for wiki autogeneration.
[arvados.git] / lib / google / api_client / discovery / api.rb
index 6ee8704624bb01e35e5bc6bda4e390c5de675079..8abea2d04efce5b548960e978d344cc045712b1e 100644 (file)
@@ -62,7 +62,10 @@ module Google
       #
       # @return [String] The service id.
       def id
-        return @discovery_document['id']
+        return (
+          @discovery_document['id'] ||
+          "#{self.name}:#{self.version}"
+        )
       end
 
       ##
@@ -82,21 +85,54 @@ module Google
       end
 
       ##
-      # Returns the parsed section of the discovery document that applies to
-      # this version of the service.
+      # Returns a human-readable title for the API.
       #
-      # @return [Hash] The service description.
+      # @return [Hash] The API title.
+      def title
+        return @discovery_document['title']
+      end
+
+      ##
+      # Returns a human-readable description of the API.
+      #
+      # @return [Hash] The API description.
       def description
         return @discovery_document['description']
       end
 
+      ##
+      # Returns a URI for the API documentation.
+      #
+      # @return [Hash] The API documentation.
+      def documentation
+        return Addressable::URI.parse(@discovery_document['documentationLink'])
+      end
+
       ##
       # Returns true if this is the preferred version of this API.
       #
       # @return [TrueClass, FalseClass]
       #   Whether or not this is the preferred version of this API.
       def preferred
-        return @discovery_document['preferred']
+        return !!@discovery_document['preferred']
+      end
+
+      ##
+      # Returns the list of API features.
+      #
+      # @return [Array]
+      #   The features supported by this API.
+      def features
+        return @discovery_document['features'] || []
+      end
+
+      ##
+      # Returns true if this API uses a data wrapper.
+      #
+      # @return [TrueClass, FalseClass]
+      #   Whether or not this API uses a data wrapper.
+      def data_wrapper?
+        return self.features.include?('dataWrapper')
       end
 
       ##
@@ -142,14 +178,29 @@ module Google
       def schemas
         return @schemas ||= (
           (@discovery_document['schemas'] || []).inject({}) do |accu, (k, v)|
-            accu[k] = Google::APIClient::Schema.new(
-              self, self.name, self.version, v
-            )
+            accu[k] = Google::APIClient::Schema.parse(self, v)
             accu
           end
         )
       end
 
+      ##
+      # Returns a schema for a kind value.
+      #
+      # @return [Google::APIClient::Schema] The associated Schema object.
+      def schema_for_kind(kind)
+        api_name, schema_name = kind.split('#', 2)
+        if api_name != self.name
+          raise ArgumentError,
+            "The kind does not match this API. " +
+            "Expected '#{self.name}', got '#{api_name}'."
+        end
+        for k, v in self.schemas
+          return v if k.downcase == schema_name.downcase
+        end
+        return nil
+      end
+
       ##
       # A list of resources available at the root level of this version of the
       # API.
@@ -180,6 +231,12 @@ module Google
         )
       end
 
+      ##
+      # Allows deep inspection of the discovery document.
+      def [](key)
+        return @discovery_document[key]
+      end
+
       ##
       # Converts the service to a flat mapping of RPC names and method objects.
       #