aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-09-05 07:13:09 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-09-11 21:58:31 +0200
commit02f64895728fe9aee2c696a627e0bbe27a24faf2 (patch)
treeab4bd15600ff6010ed20dacaa1d06f7123b2f56b /src
parentc98db1b653b5dc8b701422190b02d9fbf10c4e68 (diff)
downloadwallabag-02f64895728fe9aee2c696a627e0bbe27a24faf2.tar.gz
wallabag-02f64895728fe9aee2c696a627e0bbe27a24faf2.tar.zst
wallabag-02f64895728fe9aee2c696a627e0bbe27a24faf2.zip
Retrieve all items from Pocket
5000 by 5000. Also, retrieve newest item first.
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/ImportBundle/Import/PocketImport.php37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php
index dd0ddd72..06a31813 100644
--- a/src/Wallabag/ImportBundle/Import/PocketImport.php
+++ b/src/Wallabag/ImportBundle/Import/PocketImport.php
@@ -16,7 +16,9 @@ class PocketImport extends AbstractImport
16 private $consumerKey; 16 private $consumerKey;
17 private $skippedEntries = 0; 17 private $skippedEntries = 0;
18 private $importedEntries = 0; 18 private $importedEntries = 0;
19 protected $accessToken; 19 private $accessToken;
20
21 const NB_ELEMENTS = 5000;
20 22
21 public function __construct(EntityManager $em, ContentProxy $contentProxy, Config $craueConfig) 23 public function __construct(EntityManager $em, ContentProxy $contentProxy, Config $craueConfig)
22 { 24 {
@@ -27,6 +29,16 @@ class PocketImport extends AbstractImport
27 } 29 }
28 30
29 /** 31 /**
32 * Only used for test purpose
33 *
34 * @return string
35 */
36 public function getAccessToken()
37 {
38 return $this->accessToken;
39 }
40
41 /**
30 * {@inheritdoc} 42 * {@inheritdoc}
31 */ 43 */
32 public function getName() 44 public function getName()
@@ -114,8 +126,10 @@ class PocketImport extends AbstractImport
114 /** 126 /**
115 * {@inheritdoc} 127 * {@inheritdoc}
116 */ 128 */
117 public function import() 129 public function import($offset = 0)
118 { 130 {
131 static $run = 0;
132
119 $request = $this->client->createRequest('POST', 'https://getpocket.com/v3/get', 133 $request = $this->client->createRequest('POST', 'https://getpocket.com/v3/get',
120 [ 134 [
121 'body' => json_encode([ 135 'body' => json_encode([
@@ -123,7 +137,9 @@ class PocketImport extends AbstractImport
123 'access_token' => $this->accessToken, 137 'access_token' => $this->accessToken,
124 'detailType' => 'complete', 138 'detailType' => 'complete',
125 'state' => 'all', 139 'state' => 'all',
126 'sort' => 'oldest', 140 'sort' => 'newest',
141 'count' => self::NB_ELEMENTS,
142 'offset' => $offset,
127 ]), 143 ]),
128 ] 144 ]
129 ); 145 );
@@ -140,11 +156,20 @@ class PocketImport extends AbstractImport
140 156
141 if ($this->producer) { 157 if ($this->producer) {
142 $this->parseEntriesForProducer($entries['list']); 158 $this->parseEntriesForProducer($entries['list']);
143 159 } else {
144 return true; 160 $this->parseEntries($entries['list']);
145 } 161 }
146 162
147 $this->parseEntries($entries['list']); 163 // if we retrieve exactly the amount of items requested it means we can get more
164 // re-call import and offset item by the amount previous received:
165 // - first call get 5k offset 0
166 // - second call get 5k offset 5k
167 // - and so on
168 if (count($entries['list']) === self::NB_ELEMENTS) {
169 ++$run;
170
171 return $this->import(self::NB_ELEMENTS * $run);
172 }
148 173
149 return true; 174 return true;
150 } 175 }