1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 13:12:41 +00:00

Implement NextCloud News version detection

- Improves #47
- Still needs wrapping to actually output to clients
This commit is contained in:
J. King 2017-03-19 21:50:00 -04:00
parent 20abd277eb
commit 536fa5c4fd
6 changed files with 66 additions and 8 deletions

View file

@ -1,11 +1,25 @@
<?php
declare(strict_types=1);
namespace JKingWeb\NewsSync\REST\NextCloudNews;
use JKingWeb\NewsSync\REST\Response;
class Versions implements \JKingWeb\NewsSync\REST\Handler {
function __construct(\JKingWeb\NewsSync\RuntimeData $data) {
}
function dispatch(\JKingWeb\NewsSync\REST\Request $req): \JKingWeb\NewsSync\REST\Response {
$path = $req->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);
}
}
}

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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

View file

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace JKingWeb\NewsSync;
use JKingWeb\NewsSync\Rest\Request;
use JKingWeb\NewsSync\Rest\Response;
class TestNCNVersionDiscovery extends \PHPUnit\Framework\TestCase {
use Test\Tools;
function setUp() {
$conf = new Conf();
$this->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);
}
}

View file

@ -35,4 +35,8 @@
<file>Db/SQLite3/TestDbUpdateSQLite3.php</file>
</testsuite>
<testsuite name="NextCloud News API">
<file>REST/NextCloudNews/TestNCNVersionDiscovery.php</file>
</testsuite>
</phpunit>