Exemplo n.º 1
0
 /**
  * @return StatusPingTransfer
  */
 public function ping()
 {
     $endpoint = new Ping($this->getTransport());
     $result = $endpoint->performRequest();
     Response::checkBody($result);
     return StatusPingTransfer::make($result['json']);
 }
 /**
  * @param WarehouseAddTransfer $data
  *
  * @return int
  * @throws \Hitmeister\Component\Api\Exceptions\ServerException
  *
  */
 public function post(WarehouseAddTransfer $data)
 {
     $endpoint = new Post($this->getTransport());
     $endpoint->setTransfer($data);
     $resultRequest = $endpoint->performRequest();
     return Response::extractId($resultRequest, '/warehouses/%d/');
 }
Exemplo n.º 3
0
 /**
  * @param int    $orderUnitId
  * @param string $text
  * @return int
  */
 public function post($orderUnitId, $text)
 {
     $data = new ClaimAddTransfer();
     $data->id_order_unit = (int) $orderUnitId;
     $data->text = $text;
     $endpoint = new Post($this->getTransport());
     $endpoint->setTransfer($data);
     $resultRequest = $endpoint->performRequest();
     return Response::extractId($resultRequest, '/claims/%d/');
 }
 /**
  * @param int    $claimId
  * @param string $text
  * @return int
  */
 public function post($claimId, $text)
 {
     $data = new ClaimMessageAddTransfer();
     $data->id_claim = (int) $claimId;
     $data->text = $text;
     $endpoint = new Post($this->getTransport());
     $endpoint->setTransfer($data);
     $resultRequest = $endpoint->performRequest();
     return Response::extractId($resultRequest, '/claim-messages/%d/');
 }
 /**
  * @param string $url
  * @param string $type
  * @return int
  */
 public function post($url, $type = 'COMMAND')
 {
     $data = new ImportFileAddTransfer();
     $data->uri = $url;
     $data->type = $type;
     $endpoint = new Post($this->getTransport());
     $endpoint->setTransfer($data);
     $resultRequest = $endpoint->performRequest();
     return Response::extractId($resultRequest, '/import-files/%d/');
 }
 /**
  * @param string $eventName
  * @param string $callbackUrl
  * @param string $fallbackEmail
  * @return int
  */
 public function post($eventName, $callbackUrl, $fallbackEmail)
 {
     $data = new SubscriptionAddTransfer();
     $data->event_name = $eventName;
     $data->callback_url = $callbackUrl;
     $data->fallback_email = $fallbackEmail;
     $endpoint = new Post($this->getTransport());
     $endpoint->setTransfer($data);
     $resultRequest = $endpoint->performRequest();
     return Response::extractId($resultRequest, '/subscriptions/%d/');
 }
Exemplo n.º 7
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'];
 }
 /**
  * @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;
 }
Exemplo n.º 9
0
 /**
  * @param array                $statuses
  * @param \DateTime|int|string $dateTimeFrom
  * @param \DateTime|int|string $dateTimeTo
  * @return int
  * @throws \Hitmeister\Component\Api\Exceptions\ServerException
  */
 public function sales(array $statuses, $dateTimeFrom, $dateTimeTo)
 {
     $data = new ReportRequestSalesTransfer();
     $data->status = $statuses;
     $data->ts_from = Request::formatDateTime($dateTimeFrom);
     $data->ts_to = Request::formatDateTime($dateTimeTo);
     $endpoint = new Sales($this->getTransport());
     $endpoint->setTransfer($data);
     $resultRequest = $endpoint->performRequest();
     return Response::extractId($resultRequest, '/reports/%d/');
 }
Exemplo n.º 10
0
 public function testExtractId()
 {
     $body = ['headers' => ['Location' => ['/claim-messages/15/']]];
     $id = Response::extractId($body, '/claim-messages/%d/');
     $this->assertEquals(15, $id);
 }
Exemplo n.º 11
0
 /**
  * @param array|UnitAddTransfer $data
  * @return int
  */
 public function post($data)
 {
     if (!$data instanceof UnitAddTransfer) {
         if (!is_array($data)) {
             throw new InvalidArgumentException('Data argument should be an array of instance of UnitAddTransfer');
         }
         $data = UnitAddTransfer::make($data);
     }
     $endpoint = new Post($this->getTransport());
     $endpoint->setTransfer($data);
     $resultRequest = $endpoint->performRequest();
     return Response::extractId($resultRequest, '/units/%d/');
 }
Exemplo n.º 12
0
 /**
  *
  */
 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']);
 }