summaryrefslogtreecommitdiff
path: root/src/Flight/Helper.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/Helper.php
Inital CommitHEADmaster
Diffstat (limited to 'src/Flight/Helper.php')
-rw-r--r--src/Flight/Helper.php52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/Flight/Helper.php b/src/Flight/Helper.php
new file mode 100644
index 0000000..91a2cab
--- /dev/null
+++ b/src/Flight/Helper.php
@@ -0,0 +1,52 @@
+<?php
+
+namespace FBeans\Blaflight\Flight;
+
+class Helper
+{
+ protected $client;
+
+ protected $flights;
+
+ public function __construct(string $access_key)
+ {
+ $this->client = $this->createClient()->withAccessKey($access_key);
+ }
+
+ protected function createClient()
+ {
+ return new AviationStackClient();
+ }
+
+ public function getFlights()
+ {
+ if (!$this->flights) {
+ $this->flights = $this->client->get('/flights');
+ }
+
+ return $this->flights;
+ }
+
+ public function getFlightByIata(string $iata)
+ {
+ $flights = $this->getFlights();
+
+ foreach ($flights->data as $flight) {
+ if ($flight->flight->iata == $iata) {
+ return $this->getNiceFlightData($flight);
+ }
+ }
+
+ return false;
+ }
+
+ protected function getNiceFlightData($flight)
+ {
+ return '(' . $flight->flight_status . ')'
+ . ' ' . $flight->departure->iata
+ . '->' . $flight->arrival->iata
+ . '. Dept: ' . $flight->departure->scheduled
+ . '. Arr: ' . $flight->arrival->scheduled
+ . '. ' . $flight->airline->name;
+ }
+}