diff options
author | Jeremy Benoist <j0k3r@users.noreply.github.com> | 2016-10-12 14:06:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-12 14:06:33 +0200 |
commit | b1b561da518ae3add4445c46ef8398a314c8de37 (patch) | |
tree | 3ff96d8cfe8021d6fbaa487dd0db2ef01f74ba42 /src/Wallabag/ApiBundle | |
parent | e4cf672ccf61689ba28c2e89fc55f83167800b18 (diff) | |
parent | 3f3a60879e168f4a8040c441e295fa63e024961d (diff) | |
download | wallabag-b1b561da518ae3add4445c46ef8398a314c8de37.tar.gz wallabag-b1b561da518ae3add4445c46ef8398a314c8de37.tar.zst wallabag-b1b561da518ae3add4445c46ef8398a314c8de37.zip |
Merge pull request #2372 from pmartin/api-get-entry-as-epub
API: ability to export entry in all available format (epub, pdf, etc...)
Diffstat (limited to 'src/Wallabag/ApiBundle')
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/WallabagRestController.php | 29 | ||||
-rw-r--r-- | src/Wallabag/ApiBundle/Resources/config/routing_rest.yml | 8 |
2 files changed, 31 insertions, 6 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 9997913d..fa573988 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php | |||
@@ -3,7 +3,7 @@ | |||
3 | namespace Wallabag\ApiBundle\Controller; | 3 | namespace Wallabag\ApiBundle\Controller; |
4 | 4 | ||
5 | use FOS\RestBundle\Controller\FOSRestController; | 5 | use FOS\RestBundle\Controller\FOSRestController; |
6 | use Hateoas\Configuration\Route; | 6 | use Hateoas\Configuration\Route as HateoasRoute; |
7 | use Hateoas\Representation\Factory\PagerfantaFactory; | 7 | use Hateoas\Representation\Factory\PagerfantaFactory; |
8 | use Nelmio\ApiDocBundle\Annotation\ApiDoc; | 8 | use Nelmio\ApiDocBundle\Annotation\ApiDoc; |
9 | use Symfony\Component\HttpFoundation\Request; | 9 | use Symfony\Component\HttpFoundation\Request; |
@@ -12,6 +12,7 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | |||
12 | use Symfony\Component\Security\Core\Exception\AccessDeniedException; | 12 | use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
13 | use Wallabag\CoreBundle\Entity\Entry; | 13 | use Wallabag\CoreBundle\Entity\Entry; |
14 | use Wallabag\CoreBundle\Entity\Tag; | 14 | use Wallabag\CoreBundle\Entity\Tag; |
15 | use FOS\RestBundle\Controller\Annotations\Route; | ||
15 | 16 | ||
16 | class WallabagRestController extends FOSRestController | 17 | class WallabagRestController extends FOSRestController |
17 | { | 18 | { |
@@ -115,7 +116,7 @@ class WallabagRestController extends FOSRestController | |||
115 | $pagerfantaFactory = new PagerfantaFactory('page', 'perPage'); | 116 | $pagerfantaFactory = new PagerfantaFactory('page', 'perPage'); |
116 | $paginatedCollection = $pagerfantaFactory->createRepresentation( | 117 | $paginatedCollection = $pagerfantaFactory->createRepresentation( |
117 | $pager, | 118 | $pager, |
118 | new Route( | 119 | new HateoasRoute( |
119 | 'api_get_entries', | 120 | 'api_get_entries', |
120 | [ | 121 | [ |
121 | 'archive' => $isArchived, | 122 | 'archive' => $isArchived, |
@@ -158,6 +159,30 @@ class WallabagRestController extends FOSRestController | |||
158 | } | 159 | } |
159 | 160 | ||
160 | /** | 161 | /** |
162 | * Retrieve a single entry as a predefined format. | ||
163 | * | ||
164 | * @ApiDoc( | ||
165 | * requirements={ | ||
166 | * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} | ||
167 | * } | ||
168 | * ) | ||
169 | * | ||
170 | * @Route(requirements={"_format"="epub|mobi|pdf|txt|csv"}) | ||
171 | * | ||
172 | * @return Response | ||
173 | */ | ||
174 | public function getEntryExportAction(Entry $entry, Request $request) | ||
175 | { | ||
176 | $this->validateAuthentication(); | ||
177 | $this->validateUserAccess($entry->getUser()->getId()); | ||
178 | |||
179 | return $this->get('wallabag_core.helper.entries_export') | ||
180 | ->setEntries($entry) | ||
181 | ->updateTitle('entry') | ||
182 | ->exportAs($request->attributes->get('_format')); | ||
183 | } | ||
184 | |||
185 | /** | ||
161 | * Create an entry. | 186 | * Create an entry. |
162 | * | 187 | * |
163 | * @ApiDoc( | 188 | * @ApiDoc( |
diff --git a/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml b/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml index 5f43f971..35f8b2c1 100644 --- a/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml +++ b/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml | |||
@@ -1,4 +1,4 @@ | |||
1 | entries: | 1 | api: |
2 | type: rest | 2 | type: rest |
3 | resource: "WallabagApiBundle:WallabagRest" | 3 | resource: "WallabagApiBundle:WallabagRest" |
4 | name_prefix: api_ | 4 | name_prefix: api_ |