-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from czqoocavatsim/dev
network work
- Loading branch information
Showing
9 changed files
with
151 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace App\Services; | ||
|
||
use GuzzleHttp\Client; | ||
use Illuminate\Support\Facades\Cache; | ||
|
||
class VATSIMClient | ||
{ | ||
public function getVATSIMData() | ||
{ | ||
$client = new Client(); | ||
$responseStatus = $client->get('https://status.vatsim.net/status.json'); | ||
$dataUrl = json_decode($responseStatus->getBody())->data->v3[0]; | ||
|
||
$response = $client->get($dataUrl); | ||
|
||
if ($response->getStatusCode() === 200) { | ||
return json_decode($response->getBody()); | ||
} | ||
} | ||
|
||
public function searchCallsign($callsign, $precise) | ||
{ | ||
$data = Cache::remember('vatsimdata', 55, function () { | ||
return $this->getVATSIMData(); | ||
}); | ||
|
||
$controllers = []; | ||
|
||
foreach ($data->controllers as $controller) { | ||
if ($precise) { | ||
if ($controller->callsign == $callsign) { | ||
return $controller; | ||
} | ||
} else { | ||
$controllerCallsignParts = explode('_', $controller->callsign); | ||
$callsignParts = explode('_', $callsign); | ||
if (($controllerCallsignParts[0] === $callsignParts[0]) && (end($controllerCallsignParts) === end($callsignParts))) { | ||
array_push($controllers, $controller); | ||
} | ||
} | ||
} | ||
|
||
if ($precise) { | ||
return false; | ||
} | ||
|
||
return $controllers; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
database/migrations/2023_06_18_060444_add_callsign_column_to_session_logs_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::table('session_logs', function (Blueprint $table) { | ||
$table->string('callsign'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::table('session_logs', function (Blueprint $table) { | ||
$table->dropColumn('callsign'); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters