Bläddra i källkod

Merge remote-tracking branch 'cloudson/api_docs'

Jordi Boggiano 9 år sedan
förälder
incheckning
518c3889b0

+ 31 - 0
src/Packagist/WebBundle/Controller/ApiDocController.php

@@ -0,0 +1,31 @@
+<?php
+
+/*
+ * This file is part of Packagist.
+ *
+ * (c) Jordi Boggiano <j.boggiano@seld.be>
+ *     Nils Adermann <naderman@naderman.de>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Packagist\WebBundle\Controller;
+
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
+
+/**
+ * @author Jordi Boggiano <j.boggiano@seld.be> 
+ */
+class ApiDocController extends Controller
+{
+    /**
+     * @Template()
+     * @Route("/apidoc", name="api_doc")
+     */
+    public function indexAction()
+    {
+        return array();
+    }
+}

+ 1 - 0
src/Packagist/WebBundle/Resources/translations/messages.en.yml

@@ -12,6 +12,7 @@ menu:
     github: GitHub
     contact: Contact
     stats: Statistics
+    api_doc: Api doc
 
 link_type:
     require: Requires

+ 101 - 0
src/Packagist/WebBundle/Resources/views/ApiDoc/index.html.twig

@@ -0,0 +1,101 @@
+{% extends "PackagistWebBundle::layout.html.twig" %}
+{% block content %}
+
+<h2 class="title">API documentation</h2>
+<p>Packagist has a public API to consume data. See bellow the most important 
+URIs: <br/>
+
+<ul>
+<li><a href="#list-packages-by-organization">List packages by organization</a></li>
+<li><a href="#search-packages-by-tag">Search packages by tag</a></li>
+<li><a href="#search-packages-by-name">Search packages by name</a></li>
+<li><a href="#get-package-by-name">Get a package by name</a></li>
+</ul>
+
+<section class="col-d-12">
+<h3 id="list-packages-by-organization"> List packages by organization </h3>
+<pre>
+GET https://packagist.org/packages/list.json?vendor=[vendor]
+<code>
+{
+  "packageNames": [
+    "[vendor]/[package]",
+    ...
+  ]
+}
+</code></pre>
+</section>
+
+<section class="col-d-12"> 
+<h3 id='search-packages-by-tag'>Search packages by tag </h3>
+<pre>
+GET https://packagist.org/search.json?tags=[tag]
+<code>
+{
+  "results": [
+    {
+      "name": "[vendor]/[package]",
+      "description": "[description]",
+      "url": "https://packagist.org/packages/[vendor]/[package]",
+      "repository": "[repository url]",
+      "downloads": [number of downloads],
+      "favers": [number of favers]
+    }
+    ...
+  ],
+  "total": [numbers of results]
+}
+</code>
+</section>
+
+
+<section class="col-d-12"> 
+<h3 id='search-packages-by-name'>Search packages by name </h3>
+<pre>
+GET https://packagist.org/search.json?q=[query]
+<code>
+{
+  "results" : [
+    {
+      "name": "[vendor]/[package]",
+      "description": "<description>",
+      "url": "https://packagist.org/packages/<vendor>/<package>",
+      "repository": [repository url],
+      "downloads": [number of downloads],
+      "favers": [number of favers]
+    },
+    ...
+  ],
+  "total": [number of results],
+  "next": "https://packagist.org/search.json?q=[query]&amp;page=[next page number]"
+}
+</code>
+</section>
+
+<section class="col-d-12"> 
+<h3 id='get-package-by-name'>Get package by name </h3>
+<pre>
+GET https://packagist.org/packages/[vendor]/[package].json
+<code>
+{
+  "package": {
+    "name": "[vendor]/[package],
+    "description": [description],
+    "time": [time of the last release],
+    "maintainers": [list of maintainers],
+    "versions": [list of versions and their dependencies, the same data of <a href="https://getcomposer.org/doc/01-basic-usage.md#package-versions">composer.json</a>]
+    "type": [package type],
+    "repository": [repository url],
+    "downloads": {
+      "total": [numbers of download],
+      "monthly": [numbers of download per month],
+      "daily": [numbers of download per day]
+    },
+    "favers": [number of favers]
+  }
+}
+</code>
+</section>
+
+
+{% endblock %}

+ 7 - 0
src/Packagist/WebBundle/Resources/views/layout.html.twig

@@ -168,6 +168,13 @@
                         <li><a href="{{ path('stats') }}">{{ 'menu.stats'|trans }}</a></li>
                         <li><a href="{{ path('browse') }}">{{ 'menu.browse_packages'|trans }}</a></li>
                     </ul>
+
+                    <div class="clearfix visible-xs-block"></div>
+
+                    <ul class="col-xs-3 col-md-2">
+                        <li><a href="{{ path('api_doc') }}">{{ 'menu.api_doc'|trans }}</a></li>
+                    </ul>
+
                 </div>
 
                 <div class="row">