for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace AlfredTime;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ConnectException;
/**
* ServiceApiCall
*/
class ServiceApiCall
{
* @var mixed
private $client = null;
* @var string
private $code = '';
private $data = null;
private $message = '';
* @param array $config
public function __construct(array $config = [])
$this->client = new Client($config);
}
* @return mixed
public function getCode()
return $this->code;
public function getData()
return $this->data;
public function getMessage()
return $this->message;
* @param $status
public function last($status = '')
$res = false;
switch ($status) {
case 'success':
if ($this->code >= 200 || $this->code <= 299) {
$res = true;
break;
return $res;
* @param $method
* @param $uri
* @param array $options
public function send($method, $uri = '', array $options = [])
try {
$response = $this->client->request(strtoupper($method), $uri, $options);
$this->code = $response->getStatusCode();
$this->data = json_decode($response->getBody(), true);
} catch (ConnectException $e) {
$this->message = 'cannot connect to api!';
} catch (ClientException $e) {
$this->message = $e->getResponse()->getBody();