summaryrefslogtreecommitdiff
path: root/src/Flight/AviationStackClient.php
diff options
context:
space:
mode:
authorFbenas <philbeansburton@gmail.com>2020-11-04 18:25:16 +0000
committerFbenas <philbeansburton@gmail.com>2020-11-04 18:25:16 +0000
commit6824dd8cbc1ff5c3a4072be4a0536b6d003bf1d4 (patch)
tree7ac3a83fb0cf1f90f6e0d924da928b41bc524e3c /src/Flight/AviationStackClient.php
Inital CommitHEADmaster
Diffstat (limited to 'src/Flight/AviationStackClient.php')
-rw-r--r--src/Flight/AviationStackClient.php58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/Flight/AviationStackClient.php b/src/Flight/AviationStackClient.php
new file mode 100644
index 0000000..739fa27
--- /dev/null
+++ b/src/Flight/AviationStackClient.php
@@ -0,0 +1,58 @@
+<?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());
+ }
+}