An error occurred while loading the file. Please try again.
-
Phil Burton authored6824dd8c
<?php
namespace FBeans\Blaflight\Flight;
use GuzzleHttp\Client;
class AviationStackClient
{
protected $access_key;
public function __construct(array $guzzle_params = [])
{
$this->client = new Client($guzzle_params);
}
public function withAccessKey($access_key)
{
$this->access_key = $access_key;
return $this;
}
protected function restCall(string $api_url, string $verb, array $guzzle_params)
{
if (!isset($guzzle_params['access_key'])) {
$guzzle_params['access_key'] = $this->access_key;
}
$guzzle_params['headers'] = [
'Accept' => 'application/json'
];
$guzzle_params['headers'] = ['timeout' => 60];
try {
$response = $this->client->request($verb, $api_url, $guzzle_params);
return $response;
} catch (\Exception $e) {
var_dump($e->getMessage());
die();
}
}
protected function getBaseUrl()
{
return 'http://api.aviationstack.com/v1';
}
protected function buildUrl(string $uri)
{
return $this->getBaseUrl() . $uri . '?access_key=' . $this->access_key;
}
public function get(string $uri)
{
$response = $this->restCall($this->buildUrl($uri), 'GET', []);
return json_decode($response->getBody());
}
}