Skip to content

Commit

Permalink
Version 0.2.1
Browse files Browse the repository at this point in the history
Documentation generation started when accessing the API with GET,
returning a doc page.
  • Loading branch information
Andreas Ek committed Dec 29, 2012
1 parent 3d8cc4d commit e209baf
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 7 deletions.
7 changes: 4 additions & 3 deletions README.md
Expand Up @@ -9,9 +9,10 @@ License: GPLv2

##History
```
v. Date Description
0.2 2012-12-28 Slim Framework removed
0.1 2012-12-26 Created
v. Date Description
0.2.1 2012-12-29 Documentation generator started
0.2 2012-12-28 Slim Framework removed
0.1 2012-12-26 Created
```

##Installation
Expand Down
17 changes: 14 additions & 3 deletions api/call.php
Expand Up @@ -17,14 +17,25 @@
include 'includes/templates.php';
include 'includes/messages.php';

include 'doc/doc.php';


//Check if this is called outside PHPlist auth, this should never occur!
if ( empty( $plugin->coderoot ) ){
PHPlist_API_Response::outputMessage('Not authorized! Please login with [login] and [password] as admin first!');
PHPlist_API_Response::outputErrorMessage( 'Not authorized! Please login with [login] and [password] as admin first!' );
}

//Only POST request methods allowed
//If other than POST then assume documentation report
if ( strcmp( $_SERVER['REQUEST_METHOD'], "POST") ){
PHPlist_API_Response::outputMessage('Only requests method POST is allowed here!');

$doc = new PHPlist_API_Doc();
$doc->addClass( 'PHPlist_API_Actions' );
$doc->addClass( 'PHPlist_API_Lists' );
$doc->addClass( 'PHPlist_API_Users' );
$doc->addClass( 'PHPlist_API_Templates' );
$doc->addClass( 'PHPlist_API_Messages' );
$doc->output();

}

//Check if command is empty!
Expand Down
119 changes: 119 additions & 0 deletions api/doc/doc.php
@@ -0,0 +1,119 @@
<?php


class PHPlist_API_Doc{

private $classes;

function __construct()
{
}

function addClass( $classname ){

$this->classes[] = $classname;

}

function output(){

$this->header();

foreach( $this->classes as $class ){

$reflect = new ReflectionClass( $class );
$methods = $reflect->getMethods();
foreach( $methods as $method ){

echo '<section>';
echo '<div class="page-header">';
echo '<h2>' . $method->name . '</h2>';
echo '</div>';
echo '<div class="row">';
echo '<div class="span12">';

$comment = $method->getDocComment();

$comment = str_replace( '/**', '', $comment );
$comment = str_replace( '*/', '', $comment );
$comment = str_replace( '[*', '<span class="label label-warning">', $comment );
$comment = str_replace( '[', '<span class="label label-success">', $comment );
$comment = str_replace( ']', '</span>', $comment );
$comment = str_replace( '*', '', $comment );
//$comment = str_replace( '<br><br>', '', $comment );

echo trim($comment);

echo '</div>';
echo '</div>';
echo '<br/>';
echo '<section>';
}

}

$this->footer();

exit;

}


function header(){

?>

<!DOCTYPE html>
<html>
<head>
<title>API Plugin to PHPlist</title>
<!-- Bootstrap -->
<link href="http://netdna.bootstrapcdn.com/bootswatch/2.1.1/cerulean/bootstrap.min.css" rel="stylesheet" media="screen">
</head>
<body>
<div class="container">

<p>&nbsp;</p>

<header class="jumbotron subhead" id="overview">
<div class="row">
<div class="span6">
<h1>API Plugin to PHPlist</h1>
<p class="lead">Documentation generated <?php echo date('Y-m-d H:i:s'); ?></p>
</div>
</div>
</header>
<div class="row">
<div class="span12">
<div class="well">
The following methods is called by Body Param [cmd] to the plugin URL via request method POST.
<p>
<span class="label label-warning">Required body parameter</span><br/>
<span class="label label-success">Optional body parameter</span><br/>
</p>
</div>
</div>
</div>
<?php

}

function footer(){

?>
<footer id="footer">
<p class="pull-right"><a href="#">Back to top</a></p>
</footer>
</div>
</body>
</html>

<?php

}


}


?>
13 changes: 13 additions & 0 deletions api/includes/actions.php
Expand Up @@ -2,10 +2,23 @@

class PHPlist_API_Actions{

/**
* Function to call for login.<br/>
* <p>Parameters<br/>
* [*login] loginname as an admin to PHPlist<br/>
* [*password] the password
* </p>
*/
static function login(){
PHPlist_API_Response::outputMessage( 'Welcome!' );
}

/**
* Processes the Message Queue in PHPlist.<br/>
* Perhaps this is done via CRON or manually through the admin interface?
* <p>Parameters<br/>
*
*/
static function processQueue( ){

$admin_id = $_SESSION["logindetails"]["id"];
Expand Down
8 changes: 7 additions & 1 deletion api/main.php
Expand Up @@ -11,10 +11,16 @@

<h1>API</h1>

<h2>Version 0.2</h2>
<h2>Version 0.2.1</h2>
<p>The plugin provides a REST API to PHPlist.<br/>
Development by Flowcom AB, Andreas Ek (<a href="">@EkAndreas</a>)</p>

<p>
<h2>Commands</h2>
To discover all commands to this API just make a GET request or click here:<br/>
<a href="<?php echo $url; ?>">PHPlist API Command Reference list</a><br/>
The documentation is generated in realtime.
</p>
<p>
<h2>Access</h2>
Autentication required as admin in PHPlist.<br/>
Expand Down

0 comments on commit e209baf

Please sign in to comment.