/** * @param OAuth\Consumer $consumer * @param OAuth\HttpClient $httpClient * @param Configuration $config * @param SessionStorage $session * @param Http\IRequest $httpRequest */ public function __construct(OAuth\Consumer $consumer, OAuth\HttpClient $httpClient, Configuration $config, SessionStorage $session, Nette\Http\IRequest $httpRequest) { parent::__construct($consumer, $httpClient, $config); $this->session = $session; $this->httpRequest = $httpRequest; $this->consumer->setCallbackUrl($this->getCurrentUrl()); }
public function next() { $this->itemCursor++; // if cursor points at result of next page, try to load it if ($this->itemCursor < $this->perPage || $this->itemCursor % $this->perPage !== 0) { return; } if (isset($this->resources[$this->pageCursor + 1])) { // already loaded $this->itemCursor = 0; $this->pageCursor++; return; } if ($this->loadedMaxResults()) { return; } try { $prevRequest = $this->responses[$this->pageCursor]->getRequest(); // Get all request parameters $params = $this->responses[$this->pageCursor]->request->getParameters(); // Get last record $current = Nette\Utils\ArrayHash::from($this->resources[$this->pageCursor][$this->itemCursor - 1]); // And set maximum ID $params['max_id'] = $current->id; // Get requested path $path = $prevRequest->getUrl()->getPath(); $path = ltrim($path, '/1.1/'); $response = $this->httpClient->makeRequest($prevRequest->copyWithUrl($this->client->getConfig()->createUrl('api', $path, $params)), 'HMAC-SHA1'); $this->itemCursor = 0; $this->pageCursor++; $this->responses[$this->pageCursor] = $response; $this->resources[$this->pageCursor] = $response->toArray(); } catch (\Exception $e) { $this->itemCursor--; // revert back so the user can continue if needed } }