コード例 #1
0
ファイル: Cursor.php プロジェクト: hitmeister/api-sdk-php
 /**
  *
  */
 private function fetchData()
 {
     if (!$this->apiHasNext) {
         return;
     }
     // Set limits defined by API
     $this->apiParams['limit'] = $this->apiLimit;
     $this->apiParams['offset'] = $this->apiOffset;
     // Adjust limits by user
     if (null !== $this->userLimit) {
         $expectedCount = $this->userOffset + $this->userLimit;
         $newCount = $this->apiLimit + $this->apiOffset;
         if ($newCount > $expectedCount) {
             $dx = $newCount - $expectedCount;
             $this->apiParams['limit'] -= $dx;
             if (!$this->apiParams['limit']) {
                 $this->apiHasNext = false;
                 return;
             }
         }
     }
     $this->endpoint->setParams($this->apiParams);
     $resultRequest = $this->endpoint->performRequest();
     Response::checkBody($resultRequest);
     $cursorData = Response::extractCursorPosition($resultRequest);
     $this->total = $cursorData['total'];
     // The end
     if ($cursorData['end'] == $cursorData['total'] || null !== $this->userOffset && null !== $this->userLimit && $cursorData['end'] >= $this->userOffset + $this->userLimit || 0 === count($resultRequest['json'])) {
         $this->apiHasNext = false;
     } else {
         $this->apiOffset += $this->apiLimit;
     }
     $this->rawData = array_merge($this->rawData, $resultRequest['json']);
 }
コード例 #2
0
 public function testSetParamsConvertToString()
 {
     $expectedParams = ['status' => 'new,very_new,super_new', 'statuses' => [[1, 2, 3], [4, 5, 6]]];
     $this->transport->shouldReceive('performRequest')->withArgs(['POST', 'some_endpoint', $expectedParams, null, []]);
     $this->endpoint->shouldReceive('getParamWhiteList')->andReturn(['status', 'statuses']);
     $this->endpoint->setParams(['status' => ['new', 'very_new', 'super_new'], 'statuses' => [[1, 2, 3], [4, 5, 6]]]);
     $this->endpoint->performRequest();
 }
コード例 #3
0
 /**
  * @param AbstractEndpoint $endpoint
  * @param int              $id
  * @return array|null
  */
 protected function performWithId(AbstractEndpoint $endpoint, $id)
 {
     if ($endpoint instanceof IdAware) {
         $endpoint->setId($id);
     }
     try {
         $result = $endpoint->performRequest();
     } catch (ResourceNotFoundException $e) {
         return null;
     }
     Response::checkBody($result);
     return $result['json'];
 }