380 vacentral library (#381)

* Update vaCentral library for new API server format

* Formatting

* Remove missing/unused import
This commit is contained in:
Nabeel S
2019-09-05 16:55:51 -04:00
committed by GitHub
parent 1b82ef6c88
commit 37fc761567
8 changed files with 260 additions and 244 deletions

View File

@@ -5,6 +5,8 @@ namespace App\Providers;
use App\Contracts\AirportLookup;
use App\Contracts\Metar;
use Illuminate\Support\ServiceProvider;
use VaCentral\Contracts\IVaCentral;
use VaCentral\VaCentral;
class BindServiceProviders extends ServiceProvider
{
@@ -25,5 +27,20 @@ class BindServiceProviders extends ServiceProvider
AirportLookup::class,
config('phpvms.airport_lookup')
);
$this->app->bind(
IVaCentral::class,
function ($app) {
$client = new VaCentral();
$client->setVaCentralUrl(config('vacentral.api_url'));
// Set API if exists
if (filled(config('vacentral.api_key'))) {
$client->setApiKey(config('vacentral.api_key'));
}
return $client;
}
);
}
}

View File

@@ -1,19 +0,0 @@
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use VaCentral\VaCentral;
/**
* Bootstrap the vaCentral library
*/
class vaCentralServiceProvider extends ServiceProvider
{
public function boot()
{
if (filled(config('vacentral.api_key'))) {
VaCentral::setApiKey(config('vacentral.api_key'));
}
}
}

View File

@@ -4,11 +4,18 @@ namespace App\Services\AirportLookup;
use App\Contracts\AirportLookup;
use Illuminate\Support\Facades\Log;
use VaCentral\Airport;
use VaCentral\HttpException;
use VaCentral\Contracts\IVaCentral;
use VaCentral\Exceptions\HttpException;
class VaCentralLookup extends AirportLookup
{
private $client;
public function __construct(IVaCentral $client)
{
$this->client = $client;
}
/**
* Lookup the information for an airport
*
@@ -19,10 +26,12 @@ class VaCentralLookup extends AirportLookup
public function getAirport($icao)
{
try {
return Airport::get($icao);
$airport = $this->client->getAirport($icao);
$airport->location = $airport->city;
return $airport;
} catch (HttpException $e) {
Log::error($e);
return;
return [];
}
}
}

View File

@@ -14,7 +14,6 @@ use League\Geotools\Coordinate\Coordinate;
use League\Geotools\Geotools;
use PhpUnitsOfMeasure\Exception\NonNumericValue;
use PhpUnitsOfMeasure\Exception\NonStringUnitName;
use VaCentral\Airport;
/**
* Class AnalyticsService
@@ -29,7 +28,6 @@ class AirportService extends Service
AirportLookupProvider $lookupProvider,
AirportRepository $airportRepo,
MetarProvider $metarProvider
) {
$this->airportRepo = $airportRepo;
$this->lookupProvider = $lookupProvider;
@@ -62,7 +60,7 @@ class AirportService extends Service
*
* @param string $icao ICAO
*
* @return Airport|array
* @return mixed
*/
public function lookupAirport($icao)
{