Permalink
Browse files

Added api/languages endpoint

- Provides a list of languages that may be used to create new pastes
  • Loading branch information...
weierophinney committed Nov 1, 2012
1 parent 5ab1275 commit fa228ad74e32e030a6ac7c16d69a39643169338a
Showing with 56 additions and 0 deletions.
  1. +9 −0 config/module.config.php
  2. +16 −0 src/PhlyPaste/Controller/ApiController.php
  3. +31 −0 view/phly-paste/paste/help.phtml
View
@@ -142,6 +142,15 @@
),
'may_terminate' => true,
'child_routes' => array(
+ 'languages' => array(
+ 'type' => 'Literal',
+ 'options' => array(
+ 'route' => '/languages',
+ 'defaults' => array(
+ 'action' => 'languages',
+ ),
+ ),
+ ),
'item' => array(
'type' => 'Segment',
'options' => array(
@@ -54,6 +54,22 @@ public function onDispatch(MvcEvent $e)
return parent::onDispatch($e);
}
+ public function languagesAction()
+ {
+ $request = $this->getRequest();
+ if (!$request->isGet()) {
+ return $this->createError('invalid-method');
+ }
+ $form = $this->formFactory->factory();
+ $element = $form->get('language');
+ $options = $element->getValueOptions();
+ $languages = array_keys($options);
+ $model = new JsonModel(array(
+ 'languages' => $languages,
+ ));
+ return $model;
+ }
+
public function listAction()
{
$request = $this->getRequest();
@@ -167,6 +167,37 @@ Content-Type: application/json
{"rel": "canonical", "href": "http://pages.local/paste/XYZ12ABC"},
{"rel": "self", "href": "http://pages.local/paste/api/paste/XYZ12ABC"}
]
+}
+ </pre>
+
+ <h3>GET /paste/api/languages</h3>
+
+ <p>
+ Returns a list of language strings that may be used when creating a paste.
+ </p>
+
+ <pre>
+HTTP/1.0 200 Ok
+Content-Type: application/json
+
+{
+ "languages": [
+ "apache",
+ "diff",
+ "html4strict",
+ "ini",
+ "javascript",
+ "jquery",
+ "markdown",
+ "php",
+ "text",
+ "python",
+ "ruby",
+ "bash",
+ "sql",
+ "vim",
+ "xml"
+ ]
}
</pre>
</div>

0 comments on commit fa228ad

Please sign in to comment.