Commit bb97a735 authored by thiaramus's avatar thiaramus
Browse files

Added api endpoint classes to list available echo areas, list messages from...

Added api endpoint classes to list available echo areas, list messages from the selected area, and messages itself
parent 34b423aa
<?php
/*
* webJAM - A modern JAM MessageBase Editor
* Copyright (C) 2017 Philipp Giebel (stimpy@kuehlbox.wtf)
*
* This program is free software: you can redistribute it and/or modify it under the terms of the
* GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program.
* If not, see (http://www.gnu.org/licenses/).
*
* * filename: apiEchoarea.class.php
* * description: /echoarea API endpoint class.
* * author: Roman Litvinenko (temp@thiaramus.com)
*
*/
class apiEchoarea extends mainApiParent
{
protected $allowedHttpMethods = ['GET', 'POST', 'PATCH', 'DELETE'];
private function getList() {
$areaName = $this->apiCallPath[1];
$msgbase = new messagebase();
$areas = $msgbase->getAreaList();
if (!array_key_exists($areaName, $areas)) {
$this->syntaxErrorMessage('Area ' . $areaName . ' not found');
}
$jam = new jam();
$headers = $jam->getMsgHeader($areas[$areaName]['filename']);
$this->response($headers);
}
private function getMessage() {
$areaName = $this->apiCallPath[1];
$msgId = $this->apiCallPath[2];
$msgbase = new messagebase();
$areas = $msgbase->getAreaList();
if (!array_key_exists($areaName, $areas)) {
$this->syntaxErrorMessage('Area ' . $areaName . ' not found');
}
$jam = new jam();
$message = $jam->getMessage($areas[$areaName]['filename'], $msgId);
$this->response($message);
}
private function deleteMessage() {
$this->syntaxErrorMessage('Not implemented yet (DELETE)');
}
private function editMessage() {
$this->syntaxErrorMessage('Not implemented yet (PATCH)');
}
private function newMessage() {
$this->syntaxErrorMessage('Not implemented yet (POST)');
}
public function run() {
if (!array_key_exists(1, $this->apiCallPath)) {
$this->syntaxErrorMessage();
}
if (array_key_exists(2, $this->apiCallPath)) {
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$this->getMessage();
}
if ($_SERVER['REQUEST_METHOD'] === 'PATCH') {
$this->editMessage();
}
if ($_SERVER['REQUEST_METHOD'] === 'DELETE') {
$this->deleteMessage();
}
} else {
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$this->getList();
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$this->newMessage();
}
}
}
}
\ No newline at end of file
<?php
/*
* webJAM - A modern JAM MessageBase Editor
* Copyright (C) 2017 Philipp Giebel (stimpy@kuehlbox.wtf)
*
* This program is free software: you can redistribute it and/or modify it under the terms of the
* GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program.
* If not, see (http://www.gnu.org/licenses/).
*
* * filename: apiEchoareas.class.php
* * description: /echoareas API endpoint class
* * author: Roman Litvinenko (temp@thiaramus.com)
*
*/
class apiEchoareas extends mainApiParent
{
protected $allowedHttpMethods = ['GET'];
public function run() {
$msgbase = new messagebase();
$areaList = $msgbase->getAreaList();
// Removing file names from the response.
// I don't think it is necessary for API clients to have those.
foreach ($areaList as $key => $area) {
unset($areaList[$key]['filename']);
}
$this->response($areaList);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment