2017-03-19 02:30:36 +00:00
|
|
|
<?php
|
2017-11-17 01:23:18 +00:00
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
2017-03-19 02:30:36 +00:00
|
|
|
declare(strict_types=1);
|
2019-12-05 18:02:02 +00:00
|
|
|
namespace JKingWeb\Arsse\REST\NextcloudNews;
|
2017-08-29 14:50:31 +00:00
|
|
|
|
2022-08-05 02:04:39 +00:00
|
|
|
use JKingWeb\Arsse\Misc\HTTP;
|
2018-01-05 04:08:53 +00:00
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
2020-01-20 15:40:05 +00:00
|
|
|
use Laminas\Diactoros\Response\JsonResponse as Response;
|
2017-03-19 02:30:36 +00:00
|
|
|
|
2017-07-07 12:13:03 +00:00
|
|
|
class Versions implements \JKingWeb\Arsse\REST\Handler {
|
2017-08-29 14:50:31 +00:00
|
|
|
public function __construct() {
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-03-19 02:30:36 +00:00
|
|
|
|
2018-01-05 04:08:53 +00:00
|
|
|
public function dispatch(ServerRequestInterface $req): ResponseInterface {
|
2021-06-24 15:58:50 +00:00
|
|
|
if (!preg_match("<^/?$>D", $req->getRequestTarget())) {
|
2018-01-05 04:08:53 +00:00
|
|
|
// if the request path is more than an empty string or a slash, the client is probably trying a version we don't support
|
2022-08-05 02:04:39 +00:00
|
|
|
return HTTP::respEmpty(404);
|
2018-01-05 04:08:53 +00:00
|
|
|
}
|
|
|
|
switch ($req->getMethod()) {
|
|
|
|
case "OPTIONS":
|
|
|
|
// if the request method is OPTIONS, respond accordingly
|
2022-08-05 02:04:39 +00:00
|
|
|
return HTTP::respEmpty(204, ['Allow' => "HEAD,GET"]);
|
2018-01-05 04:08:53 +00:00
|
|
|
case "GET":
|
|
|
|
// otherwise return the supported versions
|
|
|
|
$out = [
|
|
|
|
'apiLevels' => [
|
|
|
|
'v1-2',
|
2020-03-01 20:16:50 +00:00
|
|
|
],
|
2018-01-05 04:08:53 +00:00
|
|
|
];
|
|
|
|
return new Response($out);
|
|
|
|
default:
|
|
|
|
// if any other method was used, this is an error
|
2022-08-05 02:04:39 +00:00
|
|
|
return HTTP::respEmpty(405, ['Allow' => "HEAD,GET"]);
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
}
|