-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #510 from leepeuker/move-webhook-endpoints-to-api
Move webhook endpoints to the REST API
- Loading branch information
Showing
10 changed files
with
220 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Movary\HttpController\Api; | ||
|
||
use Movary\Domain\User\UserApi; | ||
use Movary\Service\Emby\EmbyScrobbler; | ||
use Movary\Util\Json; | ||
use Movary\ValueObject\Http\Request; | ||
use Movary\ValueObject\Http\Response; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class EmbyController | ||
{ | ||
public function __construct( | ||
private readonly UserApi $userApi, | ||
private readonly EmbyScrobbler $embyScrobbler, | ||
private readonly LoggerInterface $logger, | ||
) { | ||
} | ||
|
||
public function handleEmbyWebhook(Request $request) : Response | ||
{ | ||
$webhookId = $request->getRouteParameters()['id']; | ||
|
||
$userId = $this->userApi->findUserIdByEmbyWebhookId($webhookId); | ||
if ($userId === null) { | ||
return Response::createNotFound(); | ||
} | ||
|
||
$requestPayload = $request->getPostParameters()['data']; | ||
|
||
$this->logger->debug('Emby: Webhook triggered with payload: ' . $requestPayload); | ||
|
||
$this->embyScrobbler->processEmbyWebhook($userId, Json::decode($requestPayload)); | ||
|
||
return Response::createOk(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Movary\HttpController\Api; | ||
|
||
use Movary\Domain\User\UserApi; | ||
use Movary\Service\Jellyfin\JellyfinScrobbler; | ||
use Movary\Util\Json; | ||
use Movary\ValueObject\Http\Request; | ||
use Movary\ValueObject\Http\Response; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class JellyfinController | ||
{ | ||
public function __construct( | ||
private readonly UserApi $userApi, | ||
private readonly JellyfinScrobbler $jellyfinScrobbler, | ||
private readonly LoggerInterface $logger, | ||
) { | ||
} | ||
public function handleJellyfinWebhook(Request $request) : Response | ||
{ | ||
$webhookId = $request->getRouteParameters()['id']; | ||
|
||
$userId = $this->userApi->findUserIdByJellyfinWebhookId($webhookId); | ||
if ($userId === null) { | ||
return Response::createNotFound(); | ||
} | ||
|
||
$requestPayload = $request->getBody(); | ||
|
||
$this->logger->debug('Jellyfin: Webhook triggered with payload: ' . $requestPayload); | ||
|
||
$this->jellyfinScrobbler->processJellyfinWebhook($userId, Json::decode($requestPayload)); | ||
|
||
return Response::createOk(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Movary\HttpController\Api; | ||
|
||
use Movary\Domain\User\UserApi; | ||
use Movary\Service\Plex\PlexScrobbler; | ||
use Movary\Util\Json; | ||
use Movary\ValueObject\Http\Request; | ||
use Movary\ValueObject\Http\Response; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class PlexController | ||
{ | ||
public function __construct( | ||
private readonly UserApi $userApi, | ||
private readonly PlexScrobbler $plexScrobbler, | ||
private readonly LoggerInterface $logger, | ||
) { | ||
} | ||
|
||
public function handlePlexWebhook(Request $request) : Response | ||
{ | ||
$webhookId = $request->getRouteParameters()['id']; | ||
|
||
$userId = $this->userApi->findUserIdByPlexWebhookId($webhookId); | ||
if ($userId === null) { | ||
return Response::createNotFound(); | ||
} | ||
|
||
$requestPayload = $request->getPostParameters()['payload'] ?? null; | ||
if ($requestPayload === null) { | ||
return Response::createOk(); | ||
} | ||
|
||
$this->logger->debug('Plex: Webhook triggered with payload: ' . $requestPayload); | ||
|
||
$this->plexScrobbler->processPlexWebhook($userId, Json::decode((string)$requestPayload)); | ||
|
||
return Response::createOk(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters