Created
July 3, 2019 22:27
-
-
Save anoriar/7cced46b20145f2974f40585c2bcecdd to your computer and use it in GitHub Desktop.
guzzle request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Shell\Service; | |
use GuzzleHttp\Exception\ClientException; | |
use Psr\Log\LoggerInterface; | |
class DeliveryService | |
{ | |
private $logger; | |
public function __construct(LoggerInterface $logger) | |
{ | |
$this->logger = $logger; | |
} | |
public function getDeliveryServices(){ | |
$client = new \GuzzleHttp\Client(); | |
try { | |
$res = $client->request('GET', 'https://api.saferoute.ru/api/hjo46n_zqac8hj6bemnmbli_rbpphh6b/list/city.json', ['id' => 1]); | |
} catch (ClientException $e) { | |
$res = $e->getResponse(); | |
// логируем ошибку | |
} | |
$arData = json_decode($res->getBody()->getContents()); | |
if ($res->getStatusCode() == 200) { | |
// логируем успешность запроса | |
} | |
$result = [ | |
'status' => $res->getStatusCode(), | |
'message' => null, | |
'data' => $arData | |
]; | |
return $result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment