diff options
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller/PocketController.php')
-rw-r--r-- | src/Wallabag/ImportBundle/Controller/PocketController.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/Wallabag/ImportBundle/Controller/PocketController.php b/src/Wallabag/ImportBundle/Controller/PocketController.php new file mode 100644 index 00000000..a0853383 --- /dev/null +++ b/src/Wallabag/ImportBundle/Controller/PocketController.php | |||
@@ -0,0 +1,66 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\ImportBundle\Controller; | ||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
6 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
7 | |||
8 | class PocketController extends Controller | ||
9 | { | ||
10 | /** | ||
11 | * @Route("/pocket", name="import_pocket") | ||
12 | */ | ||
13 | public function indexAction() | ||
14 | { | ||
15 | return $this->render('WallabagImportBundle:Pocket:index.html.twig', [ | ||
16 | 'import' => $this->get('wallabag_import.pocket.import'), | ||
17 | ]); | ||
18 | } | ||
19 | |||
20 | /** | ||
21 | * @Route("/pocket/auth", name="import_pocket_auth") | ||
22 | */ | ||
23 | public function authAction() | ||
24 | { | ||
25 | $requestToken = $this->get('wallabag_import.pocket.import') | ||
26 | ->getRequestToken($this->generateUrl('import', [], true)); | ||
27 | |||
28 | $this->get('session')->set('import.pocket.code', $requestToken); | ||
29 | |||
30 | return $this->redirect( | ||
31 | 'https://getpocket.com/auth/authorize?request_token='.$requestToken.'&redirect_uri='.$this->generateUrl('import_pocket_callback', [], true), | ||
32 | 301 | ||
33 | ); | ||
34 | } | ||
35 | |||
36 | /** | ||
37 | * @Route("/pocket/callback", name="import_pocket_callback") | ||
38 | */ | ||
39 | public function callbackAction() | ||
40 | { | ||
41 | $message = 'Import failed, please try again.'; | ||
42 | $pocket = $this->get('wallabag_import.pocket.import'); | ||
43 | |||
44 | // something bad happend on pocket side | ||
45 | if (false === $pocket->authorize($this->get('session')->get('import.pocket.code'))) { | ||
46 | $this->get('session')->getFlashBag()->add( | ||
47 | 'notice', | ||
48 | $message | ||
49 | ); | ||
50 | |||
51 | return $this->redirect($this->generateUrl('import_pocket')); | ||
52 | } | ||
53 | |||
54 | if (true === $pocket->import()) { | ||
55 | $summary = $pocket->getSummary(); | ||
56 | $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.'; | ||
57 | } | ||
58 | |||
59 | $this->get('session')->getFlashBag()->add( | ||
60 | 'notice', | ||
61 | $message | ||
62 | ); | ||
63 | |||
64 | return $this->redirect($this->generateUrl('homepage')); | ||
65 | } | ||
66 | } | ||