-
- public function oAuthRequest($redirectUri, $callbackUri)
- {
- $client = $this->createClient();
- $request = $client->createRequest('POST', 'https://getpocket.com/v3/oauth/request',
- [
- 'body' => json_encode([
- 'consumer_key' => $this->consumerKey,
- 'redirect_uri' => $redirectUri,
- ]),
- ]
- );
-
- $response = $client->send($request);
- $values = $response->json();
-
- // store code in session for callback method
- $this->session->set('pocketCode', $values['code']);
-
- return 'https://getpocket.com/auth/authorize?request_token='.$values['code'].'&redirect_uri='.$callbackUri;
- }
-
- public function oAuthAuthorize()
- {
- $client = $this->createClient();
-
- $request = $client->createRequest('POST', 'https://getpocket.com/v3/oauth/authorize',
- [
- 'body' => json_encode([
- 'consumer_key' => $this->consumerKey,
- 'code' => $this->session->get('pocketCode'),
- ]),
- ]
- );
-
- $response = $client->send($request);
-
- return $response->json()['access_token'];
- }
-
- public function import($accessToken)
- {
- $client = $this->createClient();
- $since = (!is_null($this->user->getLastPocketImport()) ? $this->user->getLastPocketImport()->getTimestamp() : '');
-
- $request = $client->createRequest('POST', 'https://getpocket.com/v3/get',
- [
- 'body' => json_encode([
- 'consumer_key' => $this->consumerKey,
- 'access_token' => $accessToken,
- 'detailType' => 'complete',
- 'state' => 'all',
- 'sort' => 'oldest',
- 'since' => $since,
- ]),
- ]
- );
-
- $response = $client->send($request);
- $entries = $response->json();
-
- $this->parsePocketEntries($entries['list']);
-
- $this->session->getFlashBag()->add(
- 'notice',
- count($entries['list']).' entries imported'
- );
- }