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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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\AirportLookup;
use App\Contracts\Metar; use App\Contracts\Metar;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use VaCentral\Contracts\IVaCentral;
use VaCentral\VaCentral;
class BindServiceProviders extends ServiceProvider class BindServiceProviders extends ServiceProvider
{ {
@ -25,5 +27,20 @@ class BindServiceProviders extends ServiceProvider
AirportLookup::class, AirportLookup::class,
config('phpvms.airport_lookup') 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 App\Contracts\AirportLookup;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use VaCentral\Airport; use VaCentral\Contracts\IVaCentral;
use VaCentral\HttpException; use VaCentral\Exceptions\HttpException;
class VaCentralLookup extends AirportLookup class VaCentralLookup extends AirportLookup
{ {
private $client;
public function __construct(IVaCentral $client)
{
$this->client = $client;
}
/** /**
* Lookup the information for an airport * Lookup the information for an airport
* *
@ -19,10 +26,12 @@ class VaCentralLookup extends AirportLookup
public function getAirport($icao) public function getAirport($icao)
{ {
try { try {
return Airport::get($icao); $airport = $this->client->getAirport($icao);
$airport->location = $airport->city;
return $airport;
} catch (HttpException $e) { } catch (HttpException $e) {
Log::error($e); Log::error($e);
return; return [];
} }
} }
} }

View File

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

View File

@ -37,7 +37,7 @@
"league/iso3166": "2.1.*", "league/iso3166": "2.1.*",
"markrogoyski/math-php": "^0.38.0", "markrogoyski/math-php": "^0.38.0",
"myclabs/deep-copy": "1.8.*", "myclabs/deep-copy": "1.8.*",
"nabeel/vacentral": "1.*", "nabeel/vacentral": "2.x",
"nwidart/laravel-modules": "5.*", "nwidart/laravel-modules": "5.*",
"php-units-of-measure/php-units-of-measure": "2.1.*", "php-units-of-measure/php-units-of-measure": "2.1.*",
"pragmarx/version": "0.2.*", "pragmarx/version": "0.2.*",

442
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -84,7 +84,6 @@ return [
App\Providers\AuthServiceProvider::class, App\Providers\AuthServiceProvider::class,
App\Providers\EventServiceProvider::class, App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class, App\Providers\RouteServiceProvider::class,
App\Providers\vaCentralServiceProvider::class,
App\Providers\ExtendedTimezonelistProvider::class, App\Providers\ExtendedTimezonelistProvider::class,
App\Providers\MeasurementsProvider::class, App\Providers\MeasurementsProvider::class,
App\Providers\BindServiceProviders::class, App\Providers\BindServiceProviders::class,

View File

@ -12,5 +12,5 @@ return [
/* /*
* vaCentral API URL. You likely don't need to change this * vaCentral API URL. You likely don't need to change this
*/ */
'api_url' => 'https://api.vacentral.net', 'api_url' => env('VACENTRAL_API_URL', 'https://api.vacentral.net'),
]; ];