/** * {@inheritdoc} */ public function getNextRequest(ClientInterface $client, JobConfig $jobConfig, $response, $data) { $nextUrl = Utils::getDataFromPath($this->urlParam, $response, '.'); if (empty($nextUrl)) { return false; } // start_time validation // https://developer.zendesk.com/rest_api/docs/core/incremental_export#incremental-ticket-export $now = new \DateTime(); $startDateTime = \DateTime::createFromFormat('U', Url::fromString($nextUrl)->getQuery()->get('start_time')); if ($startDateTime && $startDateTime > $now->modify(sprintf("-%d minutes", self::NEXT_PAGE_FILTER_MINUTES))) { return false; } $config = $jobConfig->getConfig(); if (!$this->includeParams) { $config['params'] = []; } if (!$this->paramIsQuery) { $config['endpoint'] = $nextUrl; } else { // Create an array from the query string $responseQuery = Query::fromString(ltrim($nextUrl, '?'))->toArray(); $config['params'] = array_replace($config['params'], $responseQuery); } return $client->createRequest($config); }
/** * {@inheritdoc} */ public function getNextRequest(ClientInterface $client, JobConfig $jobConfig, $response, $data) { $nextUrl = Utils::getDataFromPath($this->urlParam, $response, '.'); if (empty($nextUrl)) { return false; } // since validation - cannot be greater than now $now = new \DateTime(); $sinceDateTime = \DateTime::createFromFormat('U', Url::fromString($nextUrl)->getQuery()->get('since')); if ($sinceDateTime && $sinceDateTime > $now) { return false; } $config = $jobConfig->getConfig(); if (!$this->includeParams) { $config['params'] = []; } if (!$this->paramIsQuery) { $config['endpoint'] = $nextUrl; } else { // Create an array from the query string $responseQuery = Query::fromString(ltrim($nextUrl, '?'))->toArray(); $config['params'] = array_replace($config['params'], $responseQuery); } return $client->createRequest($config); }
/** * {@inheritdoc} */ public function getNextRequest(ClientInterface $client, JobConfig $jobConfig, $response, $data) { if (is_null($this->getLimit($jobConfig)) && empty($data) || count($data) < $this->getLimit($jobConfig)) { $this->reset(); return false; } else { $this->page++; return $client->createRequest($this->getParams($jobConfig)); } }
/** * {@inheritdoc} */ public function getNextRequest(ClientInterface $client, JobConfig $jobConfig, $response, $data) { if (empty($data)) { $this->reset(); return false; } else { $cursor = 0; foreach ($data as $item) { $cursorVal = Utils::getDataFromPath($this->idKey, $item, '.'); if (is_null($this->max) || $cursorVal > $this->max) { $this->max = $cursorVal; } if (is_null($this->min) || $cursorVal < $this->min) { $this->min = $cursorVal; } $cursor = $this->reverse ? $this->min : $this->max; } if (0 !== $this->increment) { if (!is_numeric($cursor)) { throw new UserException("Trying to increment a pointer that is not numeric."); } $cursor += $this->increment; } $jobConfig->setParam($this->param, $cursor); return $client->createRequest($jobConfig->getConfig()); } }
/** * {@inheritdoc} */ public function getNextRequest(ClientInterface $client, JobConfig $jobConfig, $response, $data) { $nextParam = Utils::getDataFromPath($this->responseParam, $response, '.'); if (empty($nextParam)) { return false; } else { $config = $jobConfig->getConfig(); if (!$this->includeParams) { $config['params'] = []; } if (!is_null($this->scrollRequest)) { $config = $this->createScrollRequest($config, $this->scrollRequest); } $config['params'][$this->queryParam] = $nextParam; return $client->createRequest($config); } }
/** * {@inheritdoc} */ public function getNextRequest(ClientInterface $client, JobConfig $jobConfig, $response, $data) { $nextUrl = Utils::getDataFromPath($this->urlParam, $response, '.'); if (empty($nextUrl)) { return false; } else { $config = $jobConfig->getConfig(); if (!$this->includeParams) { $config['params'] = []; } if (!$this->paramIsQuery) { $config['endpoint'] = $nextUrl; } else { // Create an array from the query string $responseQuery = Query::fromString(ltrim($nextUrl, '?'))->toArray(); $config['params'] = array_replace($config['params'], $responseQuery); } return $client->createRequest($config); } }
/** * {@inheritdoc} */ public function getFirstRequest(ClientInterface $client, JobConfig $jobConfig) { return $client->createRequest($jobConfig->getConfig()); }
/** * {@inheritdoc} * @todo increase by count($data) instead of limit? Could make limit optional then */ public function getNextRequest(ClientInterface $client, JobConfig $jobConfig, $response, $data) { if (count($data) < $this->getLimit($jobConfig)) { $this->reset(); return false; } else { $this->pointer += $this->getLimit($jobConfig); return $client->createRequest($this->getParams($jobConfig)); } }
/** * Download an URL from REST or SOAP API and return its body as an object. * should handle the API call, backoff and response decoding * * @param RequestInterface $request * @return \StdClass $response */ protected function download(RequestInterface $request) { return $this->client->download($request); }