Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions classes/API/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// APIs Endpoints to be registered
require_once(__DIR__ . '/v1/User/Get.php');
require_once(__DIR__ . '/v1/Accounts.php');
require_once(__DIR__ . '/v1/Modules.php');

require_once(dirname(__DIR__) . '/AuthenticationModule.php');

Expand Down Expand Up @@ -75,6 +76,7 @@ public static function registerCoreEndpoints() {
if (\UserConfig::$apiNamespace) {
self::register(\UserConfig::$apiNamespace, 'GET', new \StartupAPI\API\v1\User\Get());
self::register(\UserConfig::$apiNamespace, 'GET', new \StartupAPI\API\v1\Accounts());
self::register(\UserConfig::$apiNamespace, 'GET', new \StartupAPI\API\v1\Modules());
}
}

Expand Down
49 changes: 49 additions & 0 deletions classes/API/v1/Modules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace StartupAPI\API\v1;

/**
* @package StartupAPI
* @subpackage API
*/
require_once(dirname(__DIR__) . '/Endpoint.php');

/**
* Returns modules available in the system
*
* @package StartupAPI
* @subpackage API
*/
class Modules extends \StartupAPI\API\Endpoint {

public function __construct() {
parent::__construct('/v1/modules', 'Returns a list of modules configured in the system');
}

public function call($values, $raw_request_body = null) {
$results = [];

foreach (\UserConfig::$all_modules as $module) {
$result = [
'id' => $module->getID(),
'title' => $module->getTitle()
];

if (is_subclass_of($module, '\AuthenticationModule', false)) {
$result['type'] = 'authentication';
$result['is_compact'] = $module->isCompact();
} else if (is_subclass_of($module, '\PaymentEngine', false)) {
$result['type'] = 'payment';
} else if (is_subclass_of($module, '\EmailModule', false)) {
$result['type'] = 'email';
} else if (is_subclass_of($module, '\StartupAPIModule', false)) {
$result['type'] = 'other';
}

$results[] = $result;
}

return $results;
}

}