diff --git a/config/modules.json b/config/modules.json index 65a8a3b..43dd56f 100755 --- a/config/modules.json +++ b/config/modules.json @@ -35,6 +35,15 @@ "markdown": { "description": "Retourne une description en markdown des différents modules de l'API", "permissions": [], + "options": { "download": true }, + "parameters": {} + }, + + + "apiBlueprint": { + "description": "Retourne une documentation de l'API au format API Blueprint.", + "permissions": [], + "options": { "download": true }, "parameters": {} } }, diff --git a/index.php b/index.php index 8bc82e1..a95fd44 100755 --- a/index.php +++ b/index.php @@ -100,9 +100,12 @@ // Api $R->post('api(?:/(.*))?', function($url){ $request = ModuleRequest::fromPost($url, $_POST); - $answer = $request->dispatch(); + $answer = $request->dispatch(); + + // Si c'est une réponse + if( $answer instanceof ModuleResponse ) + echo $answer->serialize(); - echo $answer->serialize(); }); diff --git a/manager/ModuleRequest.php b/manager/ModuleRequest.php index fc9ef46..8a5ef2b 100755 --- a/manager/ModuleRequest.php +++ b/manager/ModuleRequest.php @@ -247,7 +247,7 @@ /* (2) On affiche le contenu */ echo $returned['body']; - return false; + return true; } } diff --git a/manager/module/module.php b/manager/module/module.php index 246cf2c..ae9e9b5 100644 --- a/manager/module/module.php +++ b/manager/module/module.php @@ -49,23 +49,23 @@ /* [2] Mise en forme de la liste des modules =========================================================*/ - $markdown = "## Module List
"; + $markdown = "## Module List\n"; foreach($modules as $moduleName=>$moduleData) - $markdown .= "- $moduleName
"; + $markdown .= "- $moduleName\n"; /* [3] Mise en forme des méthodes des modules =========================================================*/ - $markdown .= '----
## Method List & Description
'; + $markdown .= "----\n## Method List & Description\n"; $count = 1; foreach($modules as $moduleName=>$moduleData){ - $markdown .= "### $count - '$moduleName' methods
"; + $markdown .= "### $count - '$moduleName' methods\n"; foreach($moduleData as $methodName=>$methodData) - $markdown .= "`$methodName` - ".$methodData['description']."
"; + $markdown .= "`$methodName` - ".$methodData['description']."\n"; - $markdown .= '----
'; + $markdown .= "----\n"; $count++; } @@ -76,12 +76,69 @@ =========================================================*/ return array( 'ModuleError' => ManagerError::Success, - 'markdown' => $markdown + 'headers' => array( + 'Content-Type' => 'text/markdown; charset=utf-8', + 'Content-Transfer-Encoding' => 'binary', + 'Content-Disposition' => 'attachment; filename=NxTIC.apib', + 'Pragma' => 'no-cache', + 'Expires' => '0' + ), + 'body' => $markdown ); } + /* RENVOIE UNE DOC API_BLUEPRINT DE L'API + * + * @return apiBlueprint Description des modules au format API Blueprint + * + */ + public static function apiBlueprint(){ + /* [1] Récupération de la configuration + =========================================================*/ + // On récupère le fichier et on le parse + $modules = json_decode( ResourceDispatcher::getResource('f/json/modules/conf'), true ); + // Gestion de l'erreur de parsage + if( $modules == null ) + return array( 'ModuleError' => ManagerError::ParsingFailed ); + + + + /* [2] Pour chaque module + =========================================================*/ + $content = ''; + foreach($modules as $module=>$methods){ + + $content .= "## $module [/$module] \n\n"; + + /* [3] Pour chaque méthode + =========================================================*/ + foreach($methods as $methName=>$method){ + $content .= "### $methName [POST /$module/$methName]\n\n"; + $content .= $method['description']."\n"; + if( count($method['permissions']) > 0) + $content .= '> Permissions `'.implode('`', $method['permissions'])."`\n\n"; + + + + } + + } + + + return array( + 'ModuleError' => ManagerError::Success, + 'headers' => array( + 'Content-Type' => 'application/octet-stream; charset=utf-8', + 'Content-Transfer-Encoding' => 'binary', + 'Content-Disposition' => 'attachment; filename=NxTIC.apib', + 'Pragma' => 'no-cache', + 'Expires' => '0' + ), + 'body' => $content + ); + } }