mirror of
https://github.com/friendica/friendica
synced 2025-04-22 16:30:11 +00:00
Add all required HTTP methods
This commit is contained in:
parent
8ae2e3caf8
commit
6236870aa4
5 changed files with 137 additions and 10 deletions
|
@ -21,6 +21,7 @@
|
|||
|
||||
namespace Friendica\Module\Api\Mastodon;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
@ -30,6 +31,11 @@ use Friendica\Module\BaseApi;
|
|||
*/
|
||||
class Statuses extends BaseApi
|
||||
{
|
||||
public static function delete(array $parameters = [])
|
||||
{
|
||||
self::unsupported('delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
|
|
|
@ -21,9 +21,6 @@
|
|||
|
||||
namespace Friendica\Module\Api\Mastodon;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
|
@ -31,17 +28,48 @@ use Friendica\Module\BaseApi;
|
|||
*/
|
||||
class Unimplemented extends BaseApi
|
||||
{
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function delete(array $parameters = [])
|
||||
{
|
||||
self::unsupported('delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function patch(array $parameters = [])
|
||||
{
|
||||
self::unsupported('patch');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function post(array $parameters = [])
|
||||
{
|
||||
self::unsupported('post');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function put(array $parameters = [])
|
||||
{
|
||||
self::unsupported('put');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
$path = DI::args()->getQueryString();
|
||||
Logger::info('Unimplemented API call', ['path' => $path]);
|
||||
$error = DI::l10n()->t('API endpoint "%s" is not implemented', $path);
|
||||
$error_description = DI::l10n()->t('The API endpoint is currently not implemented but might be in the future.');;
|
||||
$errorobj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
|
||||
System::jsonError(501, $errorobj->toArray());
|
||||
self::unsupported('get');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
namespace Friendica\Module;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Network\HTTPException;
|
||||
|
||||
|
@ -53,6 +55,32 @@ class BaseApi extends BaseModule
|
|||
}
|
||||
}
|
||||
|
||||
public static function delete(array $parameters = [])
|
||||
{
|
||||
if (!api_user()) {
|
||||
throw new HTTPException\UnauthorizedException(DI::l10n()->t('Permission denied.'));
|
||||
}
|
||||
|
||||
$a = DI::app();
|
||||
|
||||
if (!empty($a->user['uid']) && $a->user['uid'] != api_user()) {
|
||||
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
||||
}
|
||||
}
|
||||
|
||||
public static function patch(array $parameters = [])
|
||||
{
|
||||
if (!api_user()) {
|
||||
throw new HTTPException\UnauthorizedException(DI::l10n()->t('Permission denied.'));
|
||||
}
|
||||
|
||||
$a = DI::app();
|
||||
|
||||
if (!empty($a->user['uid']) && $a->user['uid'] != api_user()) {
|
||||
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
||||
}
|
||||
}
|
||||
|
||||
public static function post(array $parameters = [])
|
||||
{
|
||||
if (!api_user()) {
|
||||
|
@ -66,6 +94,29 @@ class BaseApi extends BaseModule
|
|||
}
|
||||
}
|
||||
|
||||
public static function put(array $parameters = [])
|
||||
{
|
||||
if (!api_user()) {
|
||||
throw new HTTPException\UnauthorizedException(DI::l10n()->t('Permission denied.'));
|
||||
}
|
||||
|
||||
$a = DI::app();
|
||||
|
||||
if (!empty($a->user['uid']) && $a->user['uid'] != api_user()) {
|
||||
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
||||
}
|
||||
}
|
||||
|
||||
public static function unsupported(string $method = 'all')
|
||||
{
|
||||
$path = DI::args()->getQueryString();
|
||||
Logger::info('Unimplemented API call', ['path' => $path, 'method' => $method]);
|
||||
$error = DI::l10n()->t('API endpoint %s "%s" is not implemented', $method, $path);
|
||||
$error_description = DI::l10n()->t('The API endpoint is currently not implemented but might be in the future.');;
|
||||
$errorobj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
|
||||
System::jsonError(501, $errorobj->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Log in user via OAuth1 or Simple HTTP Auth.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue