Skip to content

Instantly share code, notes, and snippets.

@pmartin
Created October 5, 2016 05:56
Show Gist options
  • Save pmartin/42e788c043ffb383d9802f201749e98d to your computer and use it in GitHub Desktop.
Save pmartin/42e788c043ffb383d9802f201749e98d to your computer and use it in GitHub Desktop.
Adding EPUB export to wallabag API
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
index af24e49..f64b4aa 100644
--- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
@@ -79,11 +79,18 @@ class WallabagRestController extends FOSRestController
*
* @return Response
*/
- public function getEntryAction(Entry $entry)
+ public function getEntryAction(Entry $entry, $_format)
{
$this->validateAuthentication();
$this->validateUserAccess($entry->getUser()->getId());
+ if ($_format === 'epub') {
+ return $this->get('wallabag_core.helper.entries_export')
+ ->setEntries($entry)
+ ->updateTitle('entry')
+ ->exportAs($_format);
+ }
+
$json = $this->get('serializer')->serialize($entry, 'json');
return $this->renderJsonResponse($json);
diff --git a/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml b/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml
index 5f43f97..9aef7e8 100644
--- a/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml
+++ b/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml
@@ -2,3 +2,5 @@ entries:
type: rest
resource: "WallabagApiBundle:WallabagRest"
name_prefix: api_
+ requirements:
+ _format: xml|json|html|epub
@pmartin
Copy link
Author

pmartin commented Oct 5, 2016

With this patch, the /api/entries/X.format API endpoint can be called with epub as format (and not only JSON) to export the EPUB version of an entry.

For instance: https://WALLABAG_INSTANCE_URL/api/entries/2343.epub?access_token=YOUR_TOKEN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment