Corrections du modèle de l'API
This commit is contained in:
parent
095a550fc5
commit
a68649303a
|
@ -5,6 +5,7 @@
|
|||
use \router\Router;
|
||||
use \manager\ResourceDispatcher;
|
||||
use \manager\ModuleRequest;
|
||||
use \manager\ModuleResponse;
|
||||
use \manager\ManagerError;
|
||||
use \manager\Database;
|
||||
use \manager\MenuManager;
|
||||
|
@ -21,9 +22,6 @@
|
|||
define('__REDIRECT__', 'Location: /dashboard/');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* [x] Gestion des utilisateurs
|
||||
=========================================================*/
|
||||
/* (1) Valeurs par defaut */
|
||||
|
@ -103,7 +101,7 @@
|
|||
$answer = $request->dispatch();
|
||||
|
||||
// Si c'est une réponse
|
||||
if( !is_bool($answer) )
|
||||
if( $answer instanceof ModuleResponse )
|
||||
echo $answer->serialize();
|
||||
|
||||
});
|
||||
|
|
|
@ -261,6 +261,7 @@
|
|||
*
|
||||
*/
|
||||
public static function fromPost($url, $post){
|
||||
|
||||
/* [0] Verification de l'authentification
|
||||
=========================================================*/
|
||||
// On definit le token
|
||||
|
@ -270,7 +271,7 @@
|
|||
/* [1] On verifie que le @path est renseigne
|
||||
=========================================================*/
|
||||
/* (1) Si le path est dans @url */
|
||||
$pathInUrl = strlen($url[0]) > 0 && preg_match('#^([\w_-]+)/([\w_-]+)/?$#', $url[0], $urlMatches);
|
||||
$pathInUrl = is_string($url[0]) && strlen($url[0]) > 0 && preg_match('#^([\w_-]+)/([\w_-]+)/?$#', $url[0], $urlMatches);
|
||||
|
||||
// On l'utilise pour le chemin
|
||||
if( $pathInUrl )
|
||||
|
@ -300,7 +301,6 @@
|
|||
if( !is_null($json) )
|
||||
$params[$name] = $json;
|
||||
}
|
||||
|
||||
/* [4] On retourne une instance de <ModuleRequest>
|
||||
=========================================================*/
|
||||
// On cree notre requete avec le token
|
||||
|
@ -456,10 +456,12 @@
|
|||
$isFile = isset($paramsdata['type']) && $paramsdata['type'] == 'FILE' && isset($_FILES[$name]);
|
||||
|
||||
/* (3) Si le paramètre est obligatoire et qu'il n'est pas donné -> erreur */
|
||||
if( !isset($params[$name]) && !$optional && !$isFile ) return false;
|
||||
if( !isset($params[$name]) && !$optional && !$isFile )
|
||||
return false;
|
||||
|
||||
/* (4) Si le type n'est pas defini, on a pas besoin de le vérifier */
|
||||
if( !isset($paramsdata['type']) ) continue;
|
||||
if( !isset($paramsdata['type']) )
|
||||
continue;
|
||||
|
||||
/* (5) Si le paramètre est optionnel et n'est pas donné */
|
||||
if( $isFile || $optional && (!isset($params[$name]) || is_null($params[$name])) ){
|
||||
|
@ -476,7 +478,8 @@
|
|||
/* (6) Si le paramètre est renseigné */
|
||||
}else
|
||||
// Si la verification est fausse, on retourne faux
|
||||
if( !Database::check($paramsdata['type'], $params[$name]) ) return false;
|
||||
if( !Database::check($paramsdata['type'], $params[$name]) )
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -128,42 +128,45 @@
|
|||
$content .= "+ Parameters\n\n";
|
||||
foreach($method['parameters'] as $argName=>$argument){
|
||||
$optional = isset($argument['optional']) && $argument['optional'] === true;
|
||||
$content .= " + _${argName}_ (${argument['type']}, ".( $optional ? 'optional' : 'required' ).") - ${argument['description']}\n";
|
||||
$content .= " + $argName (${argument['type']}, ".( $optional ? 'optional' : 'required' ).") - ${argument['description']}\n";
|
||||
}
|
||||
$content .= "\n";
|
||||
}
|
||||
|
||||
|
||||
/* (2) Requête */
|
||||
$content .= "+ Request (multipart/form-data)\n\n";
|
||||
$content .= "+ Request (multipart/form-data; boundary=xxxBOUNDARYxxx)\n\n";
|
||||
|
||||
// Header
|
||||
$content .= " + Headers\n\n";
|
||||
$content.= " Authorization: Digest {yourAccessToken}\n\n";
|
||||
$content .= " Authorization: Digest {yourAccessToken}\n";
|
||||
$content .= " Cache-Control: no-cache\n";
|
||||
|
||||
if( isset($method['parameters']) && count($method['parameters']) > 0 ){
|
||||
|
||||
// Body
|
||||
$content .= " + Body\n\n ";
|
||||
$c = 0;
|
||||
$content .= " + Body\n\n";
|
||||
foreach($method['parameters'] as $argName=>$argument){
|
||||
if( $c > 0 ) $content .= '&';
|
||||
$content .= "$argName=_${argName}_";
|
||||
$c++;
|
||||
|
||||
$content .= " --xxxBOUNDARYxxx\n";
|
||||
$content .= " Content-Disposition: form-data; name=\"$argName\"\n";
|
||||
$content .= " Content-Type: application/json\n\n";
|
||||
$content .= " @$argName\n";
|
||||
}
|
||||
$content .= "\n\n";
|
||||
$content .= " --xxxBOUNDARYxxx--\n";
|
||||
|
||||
|
||||
// Schema
|
||||
$content .= " + Schema\n\n";
|
||||
$content .= " {\n";
|
||||
foreach($method['parameters'] as $argName=>$argData)
|
||||
$content .= " \"$argName\": _${argName}_\n";
|
||||
$content .= " }\n\n";
|
||||
$content .= " \"$argName\": @$argName\n";
|
||||
$content .= " }\n";
|
||||
}
|
||||
|
||||
|
||||
/* (3) Réponse */
|
||||
$content .= "+ Response 200 (application/json)\n\n";
|
||||
$content .= "\n+ Response 200 (application/json)\n\n";
|
||||
if( isset($method['output']) && count($method['output']) > 0 ){
|
||||
|
||||
// Body
|
||||
|
@ -171,14 +174,14 @@
|
|||
$content .= " {\n";
|
||||
foreach($method['output'] as $outName=>$outData)
|
||||
$content .= " \"$outName\": @$outName\n";
|
||||
$content .= " }\n\n";
|
||||
$content .= " }\n";
|
||||
|
||||
// Schema
|
||||
$content .= " + Schema\n\n";
|
||||
$content .= " {\n";
|
||||
foreach($method['output'] as $outName=>$outData)
|
||||
$content .= " \"$outName\": @$outName\n";
|
||||
$content .= " }\n\n";
|
||||
$content .= " }\n";
|
||||
|
||||
// On explicite tous les paramètres
|
||||
$content .= " + Attributes (object)\n\n";
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
|||
{"1":{"line":0,"hash":"10a358a685d0fbdff78068d891fdd08f06011be4"},"2":{"line":1,"hash":"dad8b6bc0c54a329075ae2a5f55e188dc1fd13fa"}}
|
||||
{"1":{"line":0,"hash":"10a358a685d0fbdff78068d891fdd08f06011be4"},"2":{"line":1,"hash":"dad8b6bc0c54a329075ae2a5f55e188dc1fd13fa"},"":{"line":2,"hash":"847db4a9bf7f5397425f60a0c596910216ab8f7c"}}
|
|
@ -1 +1 @@
|
|||
349
|
||||
361
|
|
@ -22,11 +22,11 @@
|
|||
<section data-sublink='presentation'>
|
||||
|
||||
<center>
|
||||
<img src='/subfolder/f/svg/icon/st'/>
|
||||
<img src='/subfolder/f/svg/sms/st/credits'/>
|
||||
<img src='/subfolder/f/jpg/cnrs/st/credits'/>
|
||||
<img src='/subfolder/f/png/univ_midi/st/credits'/>
|
||||
<img src='/subfolder/f/png/ut2/st/credits'/>
|
||||
<img src='/f/svg/icon/st'/>
|
||||
<img src='/f/svg/sms/st/credits'/>
|
||||
<img src='/f/jpg/cnrs/st/credits'/>
|
||||
<img src='/f/png/univ_midi/st/credits'/>
|
||||
<img src='/f/png/ut2/st/credits'/>
|
||||
</center>
|
||||
|
||||
<p>Bienvenue sur la Web Application dévéloppée par des chercheurs du CNRS appartenant au LabEx SMS (Structuration des Mondes Sociaux) de l'université de Toulouse.</p>
|
||||
|
|
Loading…
Reference in New Issue