mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-23 13:59:29 +00:00
Initial commit
This commit is contained in:
commit
9e0b7eb5a1
3
README.md
Normal file
3
README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# The Comunic API
|
||||
|
||||
This project is the main Comunic RestAPI. It assures data backend support
|
1
RestControllers/.htaccess
Normal file
1
RestControllers/.htaccess
Normal file
@ -0,0 +1 @@
|
||||
Deny from all
|
28
RestControllers/changesController.php
Normal file
28
RestControllers/changesController.php
Normal 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;
|
||||
}
|
||||
}
|
82
RestControllers/listsController.php
Normal file
82
RestControllers/listsController.php
Normal 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;
|
||||
}
|
||||
}
|
56
RestControllers/sitesController.php
Normal file
56
RestControllers/sitesController.php
Normal 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;
|
||||
}
|
||||
}
|
25
RestControllers/welcomeController.php
Normal file
25
RestControllers/welcomeController.php
Normal 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
14
index.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Comunic Rest API
|
||||
*
|
||||
* Serves the data for users
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
/**
|
||||
* Page initiator
|
||||
*/
|
||||
include(__DIR__."/init.php");
|
||||
|
Loading…
Reference in New Issue
Block a user