Skip to content

Commit

Permalink
Change response of API handlers to JsonApiResponse
Browse files Browse the repository at this point in the history
These changes are non breaking and were generated by rector. Check our
custom sets & rules -> remp/crm-rector.

- Changed return type of `handle()`:
  - from `Crm\ApiModule\Response\ApiResponseInterface`
  - to `Tomaj\NetteApi\Response\ResponseInterface`.
- Changed deprecated response:
  - from `Crm\ApiModule\Api\JsonResponse`
  - to `Tomaj\NetteApi\Response\JsonApiResponse`.

remp/crm#2330 & remp/crm#2342
  • Loading branch information
markoph committed Mar 29, 2022
1 parent 3e922b9 commit b97f5fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Api/MobiletechServerProxyApiHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace Crm\MobiletechModule\Api;

use Crm\ApiModule\Api\ApiHandler;
use Crm\ApiModule\Response\ApiResponseInterface;
use Crm\ApiModule\Token\InternalToken;
use Crm\ApplicationModule\Config\ApplicationConfig;
use Crm\MobiletechModule\Models\Config;
use GuzzleHttp\Client;
use Tomaj\NetteApi\Response\ResponseInterface;

/**
* Mobiletech only allows whitelisted set of IPs to make a request to SMS gateway. To circumvent this limitation
Expand All @@ -28,7 +28,7 @@ public function params(): array
return [];
}

public function handle(array $params): ApiResponseInterface
public function handle(array $params): ResponseInterface
{
$rawXmlPayload = file_get_contents('php://input');

Expand Down
9 changes: 5 additions & 4 deletions src/Api/MobiletechWebhookApiHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Nette\Http\Response;
use Nette\Utils\DateTime;
use Tomaj\Hermes\Emitter;
use Tomaj\NetteApi\Response\ResponseInterface;
use Tracy\Debugger;
use Tracy\ILogger;

Expand Down Expand Up @@ -68,7 +69,7 @@ public function params(): array
return [];
}

public function handle(array $params): ApiResponseInterface
public function handle(array $params): ResponseInterface
{
$rawPayload = $this->rawPayload();
$payload = new \SimpleXMLElement($rawPayload);
Expand Down Expand Up @@ -118,7 +119,7 @@ private function handleReceive($payload): ApiResponseInterface
$response = new XmlResponse($result, 'message', [
'command' => 'rcv_rsp',
]);
$response->setHttpCode(Response::S200_OK);
$response->setCode(Response::S200_OK);
return $response;
}

Expand All @@ -132,7 +133,7 @@ private function handleStatus($payload): ApiResponseInterface
if (!$outbound) {
Debugger::log("Mobiletech status command referencing outbound message that doesn't exist: ". $payload->id, ILogger::WARNING);
$response = new EmptyResponse();
$response->setHttpCode(Response::S404_NOT_FOUND);
$response->setCode(Response::S404_NOT_FOUND);
return $response;
}

Expand All @@ -144,7 +145,7 @@ private function handleStatus($payload): ApiResponseInterface
$response = new XmlResponse($result, 'message', [
'command' => 'status_rsp',
]);
$response->setHttpCode(Response::S200_OK);
$response->setCode(Response::S200_OK);
return $response;
}
}

0 comments on commit b97f5fb

Please sign in to comment.