From 6824dd8cbc1ff5c3a4072be4a0536b6d003bf1d4 Mon Sep 17 00:00:00 2001 From: Fbenas Date: Wed, 4 Nov 2020 18:25:16 +0000 Subject: Inital Commit --- src/Flight/Helper.php | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/Flight/Helper.php (limited to 'src/Flight/Helper.php') 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 @@ +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; + } +} -- cgit v1.2.3