コード例 #1
0
 /**
  * @param int $start
  * @param int $maxResults
  * @return Category[]|null
  * @throws RepositoryException
  */
 public function findAll($start = 0, $maxResults = 100)
 {
     $cacheKey = self::CACHE_NAMESPACE . sha1($start . $maxResults);
     if ($this->isCacheEnabled()) {
         if ($this->cache->contains($cacheKey)) {
             return $this->cache->fetch($cacheKey);
         }
     }
     $compiledUrl = $this->baseUrl . "?start_element={$start}&num_elements={$maxResults}";
     $response = $this->client->request('GET', $compiledUrl);
     $repositoryResponse = RepositoryResponse::fromResponse($response);
     if (!$repositoryResponse->isSuccessful()) {
         throw RepositoryException::failed($repositoryResponse);
     }
     $stream = $response->getBody();
     $responseContent = json_decode($stream->getContents(), true);
     $stream->rewind();
     $result = [];
     if (!$responseContent['response']['content_categories']) {
         $responseContent['response']['content_categories'] = [];
     }
     foreach ($responseContent['response']['content_categories'] as $segmentArray) {
         $result[] = Category::fromArray($segmentArray);
     }
     if ($this->isCacheEnabled()) {
         $this->cache->save($cacheKey, $result, self::CACHE_EXPIRATION);
     }
     return $result;
 }
コード例 #2
0
 /**
  * @param RepositoryResponse $repositoryResponse
  *
  * @return self
  */
 public static function failed(RepositoryResponse $repositoryResponse)
 {
     return new self('Failed call: ' . $repositoryResponse->getError()->getError());
 }
コード例 #3
0
 /**
  * @test
  */
 public function always_contains_an_error()
 {
     $repositoryResponse = RepositoryResponse::fromResponse($this->getOKResponse());
     $this->assertInstanceOf(Error::class, $repositoryResponse->getError());
 }
コード例 #4
0
 /**
  * @param     $memberId
  * @param int $start
  * @param int $maxResults
  *
  * @return UploadJobStatus[]
  * @throws \Exception
  */
 public function getUploadHistory($memberId, $start = 0, $maxResults = 100)
 {
     $compiledUrl = $this->baseUrl . "?member_id={$memberId}&start_element={$start}&num_elements={$maxResults}";
     $response = $this->client->request('GET', $compiledUrl);
     $repositoryResponse = RepositoryResponse::fromResponse($response);
     if (!$repositoryResponse->isSuccessful()) {
         throw UploadException::failed($repositoryResponse);
     }
     if (!isset($repositoryResponse->getResponseAsArray()['response']['batch_segment_upload_job'][0])) {
         throw UploadException::missingIndex('response->batch_segment_upload_job->0');
     }
     $uploadStatuses = [];
     $responseAsArray = $repositoryResponse->getResponseAsArray();
     foreach ($responseAsArray['response']['batch_segment_upload_job'] as $response) {
         $uploadStatuses[] = UploadJobStatus::fromArray($response);
     }
     return $uploadStatuses;
 }
コード例 #5
0
 /**
  * @param $memberId
  * @param $id
  *
  * @return RepositoryResponse
  */
 public function remove($memberId, $id)
 {
     $compiledUrl = $this->baseUrl . '?member_id=' . $memberId . '&id=' . $id;
     $response = $this->client->request('DELETE', $compiledUrl);
     $repositoryResponse = RepositoryResponse::fromResponse($response);
     return $repositoryResponse;
 }
コード例 #6
0
ファイル: Report.php プロジェクト: audiens/appnexus-client
 /**
  * @param ReportTicket $reportTicket
  *
  * @return ReportStatus
  * @throws ReportException
  */
 public function getReportStatus(ReportTicket $reportTicket)
 {
     $compiledUrl = $this->baseUrl . '?id=' . $reportTicket->getReportId();
     $response = $this->client->request('GET', $compiledUrl);
     $repositoryResponse = RepositoryResponse::fromResponse($response);
     if (!$repositoryResponse->isSuccessful()) {
         throw ReportException::failed($repositoryResponse);
     }
     if (!isset($repositoryResponse->getResponseAsArray()['response']['report'])) {
         throw ReportException::missingIndex('response->report');
     }
     if (!isset($repositoryResponse->getResponseAsArray()['response']['execution_status'])) {
         throw ReportException::missingIndex('response->execution_status');
     }
     /** @var ReportStatus $reportStatus */
     $reportStatus = ReportStatus::fromArray($repositoryResponse->getResponseAsArray()['response']['report']);
     $reportStatus->setStatus($repositoryResponse->getResponseAsArray()['response']['execution_status']);
     $reportStatus->setReportId($reportTicket->getReportId());
     $reportStatus->setCached($reportTicket->getCached());
     return $reportStatus;
 }