示例#1
0
    public function testOwnController()
    {
        $response = $this->restService->simulateCall('/login', 'post');
        $this->assertEquals('{
    "status": 400,
    "error": "MissingRequiredArgumentException",
    "message": "Argument \'username\' is missing."
}', $response);
        $response = $this->restService->simulateCall('/login?username=bla', 'post');
        $this->assertEquals('{
    "status": 400,
    "error": "MissingRequiredArgumentException",
    "message": "Argument \'password\' is missing."
}', $response);
        $response = $this->restService->simulateCall('/login?username=peter&password=pwd', 'post');
        $this->assertEquals('{
    "status": 200,
    "data": true
}', $response);
        $response = $this->restService->simulateCall('/login?username=peter&password=pwd', 'get');
        $this->assertEquals('{
    "status": 400,
    "error": "RouteNotFoundException",
    "message": "There is no route for \'login\'."
}', $response);
    }
示例#2
0
    public function testAllRoutesClosures()
    {
        $restService = Server::create('/')->setClient('RestService\\InternalClient')->addGetRoute('test', function () {
            return 'getTest';
        })->addPostRoute('test', function () {
            return 'postTest';
        })->addPatchRoute('test', function () {
            return 'patchTest';
        })->addPutRoute('test', function () {
            return 'putTest';
        })->addOptionsRoute('test', function () {
            return 'optionsTest';
        })->addDeleteRoute('test', function () {
            return 'deleteTest';
        })->addHeadRoute('test', function () {
            return 'headTest';
        })->addRoute('all-test', function () {
            return 'allTest';
        });
        foreach ($restService->getClient()->methods as $method) {
            $this->assertEquals('{
    "status": 200,
    "data": "' . $method . 'Test"
}', $restService->simulateCall('/test', $method));
            $this->assertEquals('{
    "status": 200,
    "data": "allTest"
}', $restService->simulateCall('/all-test', $method));
        }
    }
示例#3
0
    public function testCustomUrl()
    {
        $restService = Server::create('/', new MyRoutes())->setClient('RestService\\InternalClient')->collectRoutes();
        $response = $restService->simulateCall('/test/test', 'get');
        $this->assertEquals('{
    "status": 200,
    "data": "test"
}', $response);
    }
    public function testSubControllerWithSlashRootParent()
    {
        $restService = Server::create('/', new MyRoutes())->setClient('RestService\\InternalClient')->addSubController('sub', new MyRoutes())->addPostRoute('login', 'postLogin')->done();
        $response = $restService->simulateCall('/sub/login?username=peter&password=pwd', 'post');
        $this->assertEquals('{
    "status": 200,
    "data": true
}', $response);
    }
示例#5
0
 * Lorenzo Mangani <*****@*****.**> QXIP B.V.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
*/
define('ROOT', realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR));
define('_HOMEREXEC', "1");
require_once "configuration.php";
date_default_timezone_set(HOMER_TIMEZONE);
ini_set('date.timezone', HOMER_TIMEZONE);
/* if defined session_name, set this */
if (defined('SESSION_NAME')) {
    session_name(SESSION_NAME);
}
session_start();
include "autoload.php";
use RestService\Server;
define('WEBROOT', preg_replace('/api(.*)$/', '', $_SERVER["REQUEST_URI"]));
Server::create(WEBROOT . 'api', 'RestApi\\Auth')->setDebugMode(false)->addGetRoute('session', 'getSession')->addPostRoute('session', 'doSession')->addDeleteRoute('session', 'doLogout')->addGetRoute('logout', 'doLogout')->addSubController('search', 'RestApi\\Search')->addPostRoute('data', 'doSearchData')->addPostRoute('method', 'doSearchMethod')->addPostRoute('message', 'doSearchMessage')->addPostRoute('transaction', 'doSearchTransaction')->addPostRoute('sharelink', 'doShareLink')->addPostRoute('share/transaction', 'doSearchShareTransaction')->addPostRoute('share/export/pcap', 'doPcapExportById')->addPostRoute('share/export/text', 'doTextExportById')->addPostRoute('export/pcap', 'doPcapExport')->addPostRoute('export/text', 'doTextExport')->addPostRoute('export/data/pcap', 'doPcapExportData')->addPostRoute('export/data/text', 'doTextExportData')->addGetRoute('data', 'getSearchData')->done()->addSubController('statistic', 'RestApi\\Statistic')->addGetRoute('method', 'getStatisticMethod')->addPostRoute('method', 'doStatisticMethod')->addPostRoute('data', 'doStatisticData')->addGetRoute('data', 'getStatisticData')->addPostRoute('ip', 'doStatisticIP')->addGetRoute('ip', 'getStatisticIP')->addPostRoute('useragent', 'doStatisticUserAgent')->addGetRoute('useragent', 'getStatisticUserAgent')->done()->addSubController('alarm', 'RestApi\\Alarm')->addGetRoute('config/get', 'getAlarmConfig')->addPostRoute('config/new', 'doNewAlarmConfig')->addPostRoute('config/edit', 'doEditAlarmConfig')->addDeleteRoute('config/delete/([0-9]+)', 'deleteAlarmConfig')->addGetRoute('list/get', 'getAlarmList')->addPostRoute('list/edit', 'doEditAlarmList')->addGetRoute('method', 'getAlarmMethod')->addPostRoute('method', 'doAlarmMethod')->addPostRoute('ip', 'doAlarmIP')->addGetRoute('ip', 'getAlarmIP')->addPostRoute('useragent', 'doAlarmUserAgent')->addGetRoute('useragent', 'getAlarmUserAgent')->done()->addSubController('report', 'RestApi\\Report')->addPostRoute('rtcp', 'doRTCPReport')->addPostRoute('log', 'doLogReport')->addPostRoute('share/log', 'doLogReportById')->addPostRoute('quality/([A-Za-z]+)', 'doQualityReport')->done()->addSubController('admin', 'RestApi\\Admin')->addGetRoute('user/get', 'getUser')->addGetRoute('user/get/([0-9A-Za-z_])', 'getUserById')->addPostRoute('user/new', 'doNewUser')->addPostRoute('user/edit', 'doEditUser')->addDeleteRoute('user/delete/([0-9]+)', 'deleteUser')->addGetRoute('alias/get', 'getAlias')->addGetRoute('user/get/([0-9A-Za-z_])', 'getAliasById')->addPostRoute('alias/new', 'doNewAlias')->addPostRoute('alias/edit', 'doEditAlias')->addDeleteRoute('alias/delete/([0-9]+)', 'deleteAlias')->addGetRoute('node/get', 'getNode')->addGetRoute('node/get/([0-9A-Za-z_])', 'getNodeById')->addPostRoute('node/new', 'doNewNode')->addPostRoute('node/edit', 'doEditNode')->addDeleteRoute('node/delete/([0-9]+)', 'deleteNode')->addGetRoute('useragent', 'getAlarmUserAgent')->done()->addSubController('profile', 'RestApi\\Profile')->addPostRoute('store/([0-9A-Za-z_-]+)', 'postIdProfile')->addPostRoute('store', 'postProfile')->addGetRoute('store/([0-9A-Za-z_-]+)', 'getIdProfile')->addGetRoute('store', 'getProfile')->addDeleteRoute('store/([0-9A-Z_-]+)', 'deleteIdProfile')->addDeleteRoute('store', 'deleteProfile')->done()->addSubController('dashboard', 'RestApi\\Dashboard')->addPostRoute('store/([0-9A-Z_-]+)', 'postIdDashboard')->addPostRoute('store', 'postDashboard')->addPostRoute('upload', 'uploadDashboard')->addGetRoute('store/1', 'newDashboard')->addPostRoute('menu/([0-9A-Z_-]+)', 'postMenuDashboard')->addGetRoute('node', 'getNode')->addGetRoute('store/([0-9A-Za-z_-]+)', 'getIdDashboard')->addGetRoute('store', 'getDashboard')->addDeleteRoute('store/([0-9A-Z_-]+)', 'deleteIdDashboard')->addDeleteRoute('store', 'deleteDashboard')->done()->run();
示例#6
0
<?php

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../inc/settings.inc.php';
use RestService\Server;
use Galactus\Rest\Server\Frontend;
Server::create('/', new Frontend($connector))->addGetRoute('feeds', 'feeds')->addGetRoute('posts', 'posts')->addGetRoute('rss', 'rss')->addPostRoute('planet/([a-z]+)/feed', 'addFeed')->run();
示例#7
0
 /**
  * Constructor
  *
  * @param string              $pTriggerUrl
  * @param string|object       $pControllerClass
  * @param \RestService\Server $pParentController
  */
 public function __construct($pTriggerUrl, $pControllerClass = null, $pParentController = null)
 {
     $this->normalizeUrl($pTriggerUrl);
     if ($pParentController) {
         $this->parentController = $pParentController;
         $this->setClient($pParentController->getClient());
         if ($pParentController->getCheckAccess()) {
             $this->setCheckAccess($pParentController->getCheckAccess());
         }
         if ($pParentController->getExceptionHandler()) {
             $this->setExceptionHandler($pParentController->getExceptionHandler());
         }
         if ($pParentController->getDebugMode()) {
             $this->setDebugMode($pParentController->getDebugMode());
         }
         if ($pParentController->getDescribeRoutes()) {
             $this->setDescribeRoutes($pParentController->getDescribeRoutes());
         }
         if ($pParentController->getControllerFactory()) {
             $this->setControllerFactory($pParentController->getControllerFactory());
         }
         $this->setHttpStatusCodes($pParentController->getHttpStatusCodes());
     } else {
         $this->setClient(new Client($this));
     }
     $this->setClass($pControllerClass);
     $this->setTriggerUrl($pTriggerUrl);
 }
示例#8
0
 /**
  * Start REST service
  *
  * @return bool
  */
 public function startRestService()
 {
     if (!$this->_restService) {
         $this->_restService = RESTServer::create('/api', 'TweetFind\\RESTfulAPI\\Controller\\Routes')->collectRoutes();
         $this->_restService->run();
         return true;
     } else {
         return false;
     }
 }
 public function __construct($url = '/')
 {
     parent::__construct($url);
     // because we need to
     $this->twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET);
 }