/** * @return StatusPingTransfer */ public function ping() { $endpoint = new Ping($this->getTransport()); $result = $endpoint->performRequest(); Response::checkBody($result); return StatusPingTransfer::make($result['json']); }
public function testCheckBody() { $body = ['json' => []]; try { Response::checkBody($body); } catch (ServerException $e) { $this->fail('Exception thrown'); } }
/** * @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']; }
/** * @param array|CategoryDecideTransfer $data * @return array|CategoryTransfer[] */ public function decide($data) { if (!$data instanceof CategoryDecideTransfer) { if (!is_array($data)) { throw new InvalidArgumentException('Data argument should be an array of instance of CategoryDecideTransfer'); } $data = CategoryDecideTransfer::make($data); } $endpoint = new Decide($this->getTransport()); $endpoint->setTransfer($data); $resultRequest = $endpoint->performRequest(); Response::checkBody($resultRequest); $result = []; foreach ($resultRequest['json'] as $item) { $result[] = CategoryTransfer::make($item); } return $result; }
/** * */ 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']); }