forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetOoklaSpeedtestServers.php
More file actions
40 lines (33 loc) · 1.04 KB
/
GetOoklaSpeedtestServers.php
File metadata and controls
40 lines (33 loc) · 1.04 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
<?php
namespace App\Actions;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Lorisleiva\Actions\Concerns\AsAction;
use Throwable;
class GetOoklaSpeedtestServers
{
use AsAction;
public function handle(): array
{
$query = [
'engine' => 'js',
'https_functional' => true,
'limit' => 20,
];
try {
$response = Http::retry(3, 250)
->timeout(5)
->get(url: 'https://www.speedtest.net/api/js/servers', query: $query);
} catch (Throwable $e) {
Log::error('Unable to retrieve Ookla servers.', [$e->getMessage()]);
return [
'⚠️ Unable to retrieve Ookla servers, check internet connection and see logs.',
];
}
return $response->collect()->mapWithKeys(function (array $item, int $key) {
return [
$item['id'] => $item['sponsor'].' ('.$item['name'].', '.$item['id'].')',
];
})->toArray();
}
}