mirror of
https://github.com/wallabag/wallabag.git
synced 2025-01-28 22:39:56 +01:00
Retrieve all items from Pocket
5000 by 5000. Also, retrieve newest item first.
This commit is contained in:
parent
c98db1b653
commit
02f6489572
@ -16,7 +16,9 @@ class PocketImport extends AbstractImport
|
||||
private $consumerKey;
|
||||
private $skippedEntries = 0;
|
||||
private $importedEntries = 0;
|
||||
protected $accessToken;
|
||||
private $accessToken;
|
||||
|
||||
const NB_ELEMENTS = 5000;
|
||||
|
||||
public function __construct(EntityManager $em, ContentProxy $contentProxy, Config $craueConfig)
|
||||
{
|
||||
@ -26,6 +28,16 @@ class PocketImport extends AbstractImport
|
||||
$this->logger = new NullLogger();
|
||||
}
|
||||
|
||||
/**
|
||||
* Only used for test purpose
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAccessToken()
|
||||
{
|
||||
return $this->accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -114,8 +126,10 @@ class PocketImport extends AbstractImport
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function import()
|
||||
public function import($offset = 0)
|
||||
{
|
||||
static $run = 0;
|
||||
|
||||
$request = $this->client->createRequest('POST', 'https://getpocket.com/v3/get',
|
||||
[
|
||||
'body' => json_encode([
|
||||
@ -123,7 +137,9 @@ class PocketImport extends AbstractImport
|
||||
'access_token' => $this->accessToken,
|
||||
'detailType' => 'complete',
|
||||
'state' => 'all',
|
||||
'sort' => 'oldest',
|
||||
'sort' => 'newest',
|
||||
'count' => self::NB_ELEMENTS,
|
||||
'offset' => $offset,
|
||||
]),
|
||||
]
|
||||
);
|
||||
@ -140,11 +156,20 @@ class PocketImport extends AbstractImport
|
||||
|
||||
if ($this->producer) {
|
||||
$this->parseEntriesForProducer($entries['list']);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
$this->parseEntries($entries['list']);
|
||||
}
|
||||
|
||||
$this->parseEntries($entries['list']);
|
||||
// if we retrieve exactly the amount of items requested it means we can get more
|
||||
// re-call import and offset item by the amount previous received:
|
||||
// - first call get 5k offset 0
|
||||
// - second call get 5k offset 5k
|
||||
// - and so on
|
||||
if (count($entries['list']) === self::NB_ELEMENTS) {
|
||||
++$run;
|
||||
|
||||
return $this->import(self::NB_ELEMENTS * $run);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -12,14 +12,6 @@ use GuzzleHttp\Stream\Stream;
|
||||
use Monolog\Logger;
|
||||
use Monolog\Handler\TestHandler;
|
||||
|
||||
class PocketImportMock extends PocketImport
|
||||
{
|
||||
public function getAccessToken()
|
||||
{
|
||||
return $this->accessToken;
|
||||
}
|
||||
}
|
||||
|
||||
class PocketImportTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $token;
|
||||
@ -49,7 +41,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
|
||||
->with('pocket_consumer_key')
|
||||
->willReturn($consumerKey);
|
||||
|
||||
$pocket = new PocketImportMock(
|
||||
$pocket = new PocketImport(
|
||||
$this->em,
|
||||
$this->contentProxy,
|
||||
$config
|
||||
|
Loading…
x
Reference in New Issue
Block a user