Initial commit

This commit is contained in:
Pierre 2017-05-17 13:48:24 +02:00
commit 9e0b7eb5a1
8 changed files with 215 additions and 0 deletions

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# The Comunic API
This project is the main Comunic RestAPI. It assures data backend support

View File

@ -0,0 +1 @@
Deny from all

View File

@ -0,0 +1,28 @@
<?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

@ -0,0 +1,82 @@
<?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

@ -0,0 +1,56 @@
<?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

@ -0,0 +1,25 @@
<?php
/**
* RestWelcome controller
*
* @author Pierre HUBERT
*/
class welcomeController {
/**
* Returns informations about the API
*
* @url GET /
* @url GET /infos
*/
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/"
);
}
}

14
index.php Normal file
View File

@ -0,0 +1,14 @@
<?php
/**
* Comunic Rest API
*
* Serves the data for users
*
* @author Pierre HUBERT
*/
/**
* Page initiator
*/
include(__DIR__."/init.php");

6
init.php Normal file
View File

@ -0,0 +1,6 @@
<?php
/**
* Page initiator
*
* @author Pierre HUBERT
*/