380 vacentral library (#381)

* Update vaCentral library for new API server format

* Formatting

* Remove missing/unused import
pull/388/head
Nabeel S 5 years ago committed by GitHub
parent 1b82ef6c88
commit 37fc761567
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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;
}
);
}
}

@ -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'));
}
}
}

@ -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 [];
}
}
}

@ -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)
{

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

442
composer.lock generated

File diff suppressed because it is too large Load Diff

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

@ -12,5 +12,5 @@ return [
/*
* 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'),
];

Loading…
Cancel
Save