summaryrefslogtreecommitdiff
path: root/src/Flight/Helper.php
diff options
context:
space:
mode:
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;
+ }
+}