public function testExtractCursor() { $body = ['headers' => ['Hm-Collection-Range' => ['6-10/5575']]]; $result = Response::extractCursorPosition($body); $this->assertEquals(6, $result['start']); $this->assertEquals(10, $result['end']); $this->assertEquals(5575, $result['total']); }
/** * */ 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']); }