diff --git a/lib/REST/NextCloudNews/Versions.php b/lib/REST/NextCloudNews/Versions.php index d0dcecd7..992d66af 100644 --- a/lib/REST/NextCloudNews/Versions.php +++ b/lib/REST/NextCloudNews/Versions.php @@ -1,11 +1,25 @@ url; + $query = ""; + if(strpos($path, "?") !== false) { + list($path, $query) = explode("?", $path); + } + if($req->method != "GET") { + return new Response(405); + } + if(preg_match("<^/?$>",$path)) { + return new Response(200, ['v1-2']); + } else { + return new Response(404); + } } } \ No newline at end of file diff --git a/lib/REST/Request.php b/lib/REST/Request.php index 7e4c9338..afc3e6de 100644 --- a/lib/REST/Request.php +++ b/lib/REST/Request.php @@ -3,17 +3,19 @@ declare(strict_types=1); namespace JKingWeb\NewsSync\REST; class Request { - public $method; - public $url; - public $type; - public $stream; + public $method = "GET"; + public $url = ""; + public $type =""; + public $stream = "php://input"; function __construct(string $method = null, string $url = null, string $bodyStream = null, string $contentType = null) { if(is_null($method)) $method = $_SERVER['REQUEST_METHOD']; if(is_null($url)) $url = $_SERVER['REQUEST_URI']; if(is_null($bodyStream)) $bodyStream = "php://input"; - if(is_null($contentType)) $contentType = $_SERVER['HTTP_CONTENT_TYPE']; - $this->method = method; + if(is_null($contentType)) { + if(isset($_SERVER['HTTP_CONTENT_TYPE'])) $contentType = $_SERVER['HTTP_CONTENT_TYPE']; + } + $this->method = strtoupper($method); $this->url = $url; $this->stream = $bodyStream; $this->type = $contentType; diff --git a/lib/REST/Response.php b/lib/REST/Response.php index 245d3fc3..bf5c4bf1 100644 --- a/lib/REST/Response.php +++ b/lib/REST/Response.php @@ -3,5 +3,20 @@ declare(strict_types=1); namespace JKingWeb\NewsSync\REST; class Response { - // stub + const T_JSON = "application/json"; + const T_XML = "application/xml"; + const T_TEXT = "text/plain"; + + public $code; + public $payload; + public $type; + public $fields; + + + function __construct(int $code, $payload = null, string $type = self::T_JSON, array $extraFields = []) { + $this->code = $code; + $this->payload = $payload; + $this->type = $type; + $this->fields = $extraFields; + } } \ No newline at end of file diff --git a/sql/SQLite3/0.sql b/sql/SQLite3/0.sql index a181f131..c02da7b4 100644 --- a/sql/SQLite3/0.sql +++ b/sql/SQLite3/0.sql @@ -74,7 +74,7 @@ create table newssync_articles( modified datetime not null default CURRENT_TIMESTAMP, -- date when article properties were last modified url_title_hash varchar(64), -- hash of URL + title; used when checking for updates and for identification if there is no guid. url_content_hash varchar(64), -- hash of URL + content, enclosure URL, & content type; used when checking for updates and for identification if there is no guid. - title_content_hash varchar(64), -- hash of title + content, enclosure URL, & content type; used when checking for updates and for identification if there is no guid. + title_content_hash varchar(64) -- hash of title + content, enclosure URL, & content type; used when checking for updates and for identification if there is no guid. ); -- enclosures associated with articles diff --git a/tests/REST/NextCloudNews/TestNCNVersionDiscovery.php b/tests/REST/NextCloudNews/TestNCNVersionDiscovery.php new file mode 100644 index 00000000..68dc0574 --- /dev/null +++ b/tests/REST/NextCloudNews/TestNCNVersionDiscovery.php @@ -0,0 +1,23 @@ +data = new Test\RuntimeData($conf); + } + + function testVersionList() { + $exp = new Response(200, ['v1-2']); + $req = new Request("GET", "/"); + $h = new Rest\NextCloudNews\Versions($this->data); + $res = $h->dispatch($req); + $this->assertEquals($exp, $res); + } +} \ No newline at end of file diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 303a5314..d1721da7 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -35,4 +35,8 @@ Db/SQLite3/TestDbUpdateSQLite3.php + + REST/NextCloudNews/TestNCNVersionDiscovery.php + + \ No newline at end of file