Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+34 -22
View File
@@ -11,16 +11,26 @@
namespace IPS\core\api;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Api\Controller;
use IPS\Api\Exception;
use IPS\Api\Response;
use IPS\Api\Webhook;
use IPS\Http\Url;
use IPS\Request;
use OutOfRangeException;
use function defined;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* @brief Webhooks API
*/
class _webhooks extends \IPS\Api\Controller
class webhooks extends Controller
{
/**
* POST /core/webhooks
@@ -30,39 +40,40 @@ class _webhooks extends \IPS\Api\Controller
* @reqapiparam array events List of events to subscribe to
* @reqapiparam string url URL to send webhook to
* @apiparam string content_header The content type for the request.
* @return \IPS\Api\Webhook
* @apireturn \IPS\Api\Webhook
* @throws 1C293/1 NO_EVENTS No events were specified
* @throws 1C293/2 INVALID_URL The URL specified was not valid
* @return Response
*/
public function POSTindex()
public function POSTindex(): Response
{
$events = \IPS\Request::i()->events;
$events = Request::i()->events;
if ( !$events )
{
throw new \IPS\Api\Exception( 'NO_EVENTS', '1C293/1', 400 );
throw new Exception( 'NO_EVENTS', '1C293/1', 400 );
}
try
{
$url = new \IPS\Http\Url( \IPS\Request::i()->url );
$url = new Url( Request::i()->url );
}
catch ( \IPS\Http\Url\Exception $e )
catch ( Url\Exception $e )
{
throw new \IPS\Api\Exception( 'INVALID_URL', '1C293/2', 400 );
throw new Exception( 'INVALID_URL', '1C293/2', 400 );
}
$webhook = new \IPS\Api\Webhook;
$webhook = new Webhook;
$webhook->api_key = $this->apiKey;
$webhook->events = $events;
$webhook->filters = ( \IPS\Request::i()->filters ?: array() );
$webhook->filters = ( Request::i()->filters ?: array() );
$webhook->url = $url;
if( \IPS\Request::i()->content_header )
if( Request::i()->content_header )
{
$webhook->content_type = \IPS\Request::i()->content_header;
$webhook->content_type = Request::i()->content_header;
}
$webhook->save();
return new \IPS\Api\Response( 201, $webhook->apiOutput() );
return new Response( 201, $webhook->apiOutput() );
}
/**
@@ -71,28 +82,29 @@ class _webhooks extends \IPS\Api\Controller
*
* @apiclientonly
* @param int $id ID Number
* @return void
* @apireturn void
* @throws 1C293/3 INVALID_ID The ID provided does not match any webhook
* @throws 3C293/4 WRONG_API_KEY The API key making this request is not the API key that created the webhook
* @return Response
*/
public function DELETEitem( $id )
public function DELETEitem( int $id ): Response
{
try
{
$webhook = \IPS\Api\Webhook::load( $id );
$webhook = Webhook::load( $id );
if ( $webhook->api_key != $this->apiKey )
{
throw new \IPS\Api\Exception( 'WRONG_API_KEY', '3C293/4', 403 );
throw new Exception( 'WRONG_API_KEY', '3C293/4', 403 );
}
$webhook->delete();
return new \IPS\Api\Response( 200, NULL );
return new Response( 200, NULL );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '1C293/3', 404 );
throw new Exception( 'INVALID_ID', '1C293/3', 404 );
}
}
}