forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOoklaListServers.php
More file actions
53 lines (44 loc) · 1.32 KB
/
OoklaListServers.php
File metadata and controls
53 lines (44 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Http;
use function Laravel\Prompts\table;
class OoklaListServers extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:ookla-list-servers
{search? : Search for a server by name}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Get a list of local Ookla speedtest servers.';
/**
* Execute the console command.
*/
public function handle(): void
{
$response = Http::retry(3, 250)->get(
url: 'https://www.speedtest.net/api/js/servers',
query: [
'engine' => 'js',
'https_functional' => true,
'search' => $this->argument('search'),
'limit' => 20, // 20 is the max returned by the api
],
);
if ($response->failed()) {
$this->fail('There was an issue retrieving a list of speedtest servers, check the logs.');
}
$fields = ['id', 'sponsor', 'name', 'country', 'distance'];
table(
headers: $fields,
rows: $response->collect()->select($fields),
);
}
}