diff --git a/composer.json b/composer.json index 3c14795..bfa65b5 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,6 @@ "ext-intl": "*", "ext-iconv": "*", "fguillot/picofeed": ">=0.1.31", - "respect/rest": "^0.6", "jkingweb/druuid": "^3.0", "phpseclib/phpseclib": "^2.0", "hosteurope/password-generator": "^1.0", diff --git a/composer.lock b/composer.lock index 1d8d84c..4953e21 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "31bedf1105f6249d6e9d990abd2125de", + "content-hash": "4afb7b406ec21a2c18f46fd176fc242f", "packages": [ { "name": "fguillot/picofeed", @@ -236,50 +236,6 @@ ], "time": "2016-10-04T00:57:04+00:00" }, - { - "name": "respect/rest", - "version": "0.6.0", - "source": { - "type": "git", - "url": "https://github.com/Respect/Rest.git", - "reference": "4f60aa199623d738a3391ca1e80bafb754bc9308" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Respect/Rest/zipball/4f60aa199623d738a3391ca1e80bafb754bc9308", - "reference": "4f60aa199623d738a3391ca1e80bafb754bc9308", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "require-dev": { - "phpunit/phpunit": "~4.4.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Respect\\": "library/Respect" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD Style" - ], - "authors": [ - { - "name": "Alexandre Gaigalas", - "email": "alexandre@gaigalas.net" - }, - { - "name": "Respect/Data Contributors", - "homepage": "https://github.com/Respect/Data/graphs/contributors" - } - ], - "description": "Thin controller for RESTful applications", - "homepage": "http://respect.li/", - "time": "2015-01-12T09:55:16+00:00" - }, { "name": "webmozart/assert", "version": "1.2.0", diff --git a/lib/REST.php b/lib/REST.php index 77ddcdd..73972e4 100644 --- a/lib/REST.php +++ b/lib/REST.php @@ -1,8 +1,53 @@ [ + 'match' => '/index.php/apps/news/api', + 'strip' => '/index.php/apps/news/api', + 'class' => REST\NextCloudNews\Versions::class, + ], + // NextCloud News v1-2 https://github.com/nextcloud/news/blob/master/docs/externalapi/Legacy.md + 'ncn_v1-2' => [ + 'match' => '/index.php/apps/news/api/v1-2/', + 'strip' => '/index.php/apps/news/api/v1-2', + 'class' => REST\NextCloudNews\V1_2::class, + ], + // Other candidates: + // NextCloud News v2 https://github.com/nextcloud/news/blob/master/docs/externalapi/External-Api.md + // Feedbin v1 https://github.com/feedbin/feedbin-api/commit/86da10aac5f1a57531a6e17b08744e5f9e7db8a9 + // Feedbin v2 https://github.com/feedbin/feedbin-api + // Tiny Tiny RSS https://tt-rss.org/gitlab/fox/tt-rss/wikis/ApiReference + // Fever https://feedafever.com/api + // NewsBlur http://www.newsblur.com/api + ]; + protected $data; + + function __construct(RuntimeData $data) { + $this->data = $data; + } + function dispatch(REST\Request $req = null): bool { + if($req===null) $req = new REST\Request(); + $api = $this->apiMatch($url, $this->apis); + $req->url = substr($url,strlen($this->apis[$api]['strip'])); + $class = $this->apis[$api]['class']; + $drv = new $class($this->data); + $drv->dispatch($req); + return true; + } + + function apiMatch(string $url, array $map): string { + // sort the API list so the longest URL prefixes come first + uasort($map, function($a, $b) {return (strlen($a['match']) <=> strlen($b['match'])) * -1;}); + // find a match + foreach($map as $id => $api) { + if(strpos($url, $api['match'])===0) return $id; + } + // or throw an exception otherwise + throw new REST\ExceptionURL("apiNotSupported", $url); + } } \ No newline at end of file diff --git a/lib/REST/Handler.php b/lib/REST/Handler.php new file mode 100644 index 0000000..cba6bcb --- /dev/null +++ b/lib/REST/Handler.php @@ -0,0 +1,8 @@ +method = method; + $this->url = $url; + $this->stream = $bodyStream; + $this->type = $contentType; + } +} \ No newline at end of file diff --git a/lib/REST/Response.php b/lib/REST/Response.php new file mode 100644 index 0000000..245d3fc --- /dev/null +++ b/lib/REST/Response.php @@ -0,0 +1,7 @@ +userAuthPreferHTTP = true; $data = new RuntimeData($conf); $data->db->schemaUpdate(); +(new REST($data))->dispatch("GET", "/index.php/apps/news/api/", ""); +exit; + + $data->user->add($user, $pass); $data->user->auth();