Implemented RestServer controller

This commit is contained in:
Pierre
2017-05-17 14:05:23 +02:00
parent 2fb7d0d43d
commit 3b0272a196
9 changed files with 642 additions and 170 deletions

View File

@ -1,28 +0,0 @@
<?php
/**
* Changes Rest Controller
*
* @author Pierre HUBERT
*/
class changesController {
/**
* Get the changes of a specified period
*
* @url GET /changes/get/$from/$to
*/
public function getChanges($from, $to){
//Check values
if($from*1 > $to*1)
Rest_fatal_error(401, "Please specify a valid interval !");
//We try to get changes of the specified period
$changes = DW::get()->changes->get($from*1, $to*1);
if($changes === false)
Rest_fatal_error(500, "Couldn't get changes of the specified period !");
//Return the informations
return $changes;
}
}

View File

@ -1,82 +0,0 @@
<?php
/**
* Lists management controller
*
* @author Pierre HUBERT
*/
class listsController {
/**
* Get the complete list
*
* @url GET /list/get
* @url GET /list/get/
* @url GET /list/get/$time
*/
public function getList($time="current"){
//We check if we want the current list or another one
if($time === "current"){
//Try to get the current list
if(!$list = DW::get()->lists->getCurrent())
Rest_fatal_error(500, "Couldn't get current list !");
}
else {
//Get the list of the specified timestamp
if(!$list = DW::get()->lists->getOnTimestamp($time*1))
Rest_fatal_error(500, "Couldn't get the list on specified timestamp !");
}
//Return the list
return $list;
}
/**
* Update the current list
*
* @url POST /list/update
*/
public function updateList(){
//Authentication required (protected method)
if(!DW::get()->auth->restAuth())
Rest_fatal_error(401, "Authentication required !");
//Try to update list
if(!DW::get()->lists->update())
Rest_fatal_error(500, "Couldn't update Decodex list !");
//Else it is a success
return array("success" => "This list was successfully updated !");
}
/**
* Get the list of available websites using urls
*
* @url GET /list/urls
*/
public function getListSites(){
//We try to get the list of urls
if(!$list = DW::get()->lists->getListUrls())
Rest_fatal_error(500, "Couldn't get the list of urls !");
//Return the list
return $list;
}
/**
* Get the list of URLs only
*
* @url GET /list/urls/only
*/
public function getURLsOnly(){
//We try to get the list of urls
if(!$list = DW::get()->lists->getListUrls(true))
Rest_fatal_error(500, "Couldn't get the list of urls !");
//Return the list
return $list;
}
}

View File

@ -1,56 +0,0 @@
<?php
/**
* Sites informations controller
*
* @author Pierre HUBERT
*/
class sitesController{
/**
* Get the informations about a website given a URL
*
* @url GET /site/$url/infos
* @url POST /site/infos
*/
public function getInfosURL($url=false){
//We check if the URL was passed in $_POST mode
if(!$url){
if(!isset($_POST['url']))
Rest_fatal_error(401, "Please specify an URL !");
$url = $_POST['url'];
}
//We try to get informations about a websites using its URL
if(!$infos = DW::get()->sites->getInfosFromURL($url))
Rest_fatal_error(500, "Couldn't get informations about the URL !");
//Return the informations
return $infos;
}
/**
* Get the informations history about a website given a URL
*
* @url GET /site/$url/history
* @url POST /site/history
*/
public function getInfosURLHistory($url=false){
//We check if the URL was passed in $_POST mode
if(!$url){
if(!isset($_POST['url']))
Rest_fatal_error(401, "Please specify an URL !");
$url = $_POST['url'];
}
//We try to get informations about a websites using its URL
if(!$infos = DW::get()->sites->getInfosFromURL($url, 0))
Rest_fatal_error(500, "Couldn't get history informations about the URL !");
//Return the informations
return $infos;
}
}

View File

@ -15,10 +15,8 @@ class welcomeController {
*/
public function getInfos(){
return array(
"serviceDescription" => "This service watches DecodexList evolutions, stores them and let its client access them.",
"githubURL" => "https://github.com/pierre42100/decodexwatcherapi/",
"clientURL" => "https://decodexwatcher.communiquons.org/",
"apiSchema" => "https://swagger.decodexwatcher.communiquons.org/"
"serviceDescription" => "This is the Comunic API Server.",
"clientURL" => "https://communiquons.org/",
);
}