Ejemplo n.º 1
0
 /**
  * @param ReportStatus $reportStatus
  *
  * @return array
  * @throws ReportException
  */
 public function getReport(ReportStatus $reportStatus)
 {
     if (!$reportStatus->isReady()) {
         throw ReportException::validation('report status not ready');
     }
     if (!$reportStatus->getUrl()) {
         throw ReportException::validation('missing url in the report status');
     }
     $cacheKey = self::CACHE_NAMESPACE . sha1($reportStatus->getUrl());
     if ($this->isCacheEnabled()) {
         if ($this->cache->contains($cacheKey)) {
             return $this->cache->fetch($cacheKey);
         }
     }
     $compiledUrl = $this->baseUrlDownload . $reportStatus->getUrl();
     $response = $this->client->request('GET', $compiledUrl);
     $lines = explode(PHP_EOL, $response->getBody()->getContents());
     $result = [];
     foreach ($lines as $line) {
         if (!empty($line)) {
             $result[] = str_getcsv($line);
         }
     }
     if ($this->isCacheEnabled()) {
         $this->cache->save($cacheKey, $result, self::CACHE_EXPIRATION);
     }
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * @test
  */
 public function should_append_the_authorization_token_when_performing_any_request()
 {
     $username = '******';
     $password = '******';
     $token = 'a_sample_token123456789';
     $dummyStream = $this->prophesize(Stream::class);
     $dummyStream->getContents("{'response:{}'}");
     $dummyResponse = $this->prophesize(Response::class);
     $dummyResponse->getBody()->willReturn($dummyStream->reveal());
     $authStrategy = $this->prophesize(AuthStrategyInterface::class);
     $authStrategy->authenticate($username, $password, Argument::any())->willReturn($token)->shouldBeCalled();
     $expectedRequestOptions = ['headers' => ['Authorization' => $token]];
     $client = $this->prophesize(ClientInterface::class);
     $client->request('POST', 'random_url', $expectedRequestOptions)->willReturn($dummyResponse->reveal())->shouldBeCalled();
     $auth = new Auth($username, $password, $client->reveal(), $authStrategy->reveal());
     $auth->request('POST', 'random_url', []);
 }
Ejemplo n.º 3
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;
 }