- initial
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once dirname(__DIR__) . '/src/bootstrap.php';
|
||||
|
||||
try {
|
||||
$action = (string) request_value('action', 'weather');
|
||||
$service = weather_service();
|
||||
|
||||
switch ($action) {
|
||||
case 'search':
|
||||
json_response([
|
||||
'ok' => true,
|
||||
'locations' => $service->searchLocations((string) request_value('q', '')),
|
||||
]);
|
||||
break;
|
||||
|
||||
case 'weather':
|
||||
json_response([
|
||||
'ok' => true,
|
||||
'dashboard' => $service->dashboard([
|
||||
'q' => request_value('q', ''),
|
||||
'lat' => request_value('lat'),
|
||||
'lon' => request_value('lon'),
|
||||
'name' => request_value('name'),
|
||||
'admin1' => request_value('admin1'),
|
||||
'country' => request_value('country'),
|
||||
'country_code' => request_value('country_code'),
|
||||
'timezone' => request_value('timezone'),
|
||||
'force' => request_value('force', false),
|
||||
]),
|
||||
]);
|
||||
break;
|
||||
|
||||
case 'archives':
|
||||
json_response([
|
||||
'ok' => true,
|
||||
'archives' => $service->listArchives([
|
||||
'q' => request_value('q', ''),
|
||||
'kind' => request_value('kind', ''),
|
||||
'start' => request_value('start', ''),
|
||||
'end' => request_value('end', ''),
|
||||
'limit' => request_value('limit', 50),
|
||||
]),
|
||||
]);
|
||||
break;
|
||||
|
||||
case 'archive':
|
||||
json_response([
|
||||
'ok' => true,
|
||||
'archive' => $service->getArchive((int) request_value('id', 0)),
|
||||
]);
|
||||
break;
|
||||
|
||||
default:
|
||||
json_response([
|
||||
'ok' => false,
|
||||
'error' => 'Unknown API action.',
|
||||
], 404);
|
||||
}
|
||||
} catch (InvalidArgumentException $error) {
|
||||
json_response([
|
||||
'ok' => false,
|
||||
'error' => $error->getMessage(),
|
||||
], 422);
|
||||
} catch (Throwable $error) {
|
||||
json_response([
|
||||
'ok' => false,
|
||||
'error' => $error->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
Reference in New Issue
Block a user