Added getSubscriptions method

This commit is contained in:
Alex
2025-07-07 21:05:18 +03:00
parent f3a7b2b3ba
commit 45020eab52
6 changed files with 148 additions and 15 deletions
+35 -4
View File
@@ -4,7 +4,12 @@ declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot;
use BushlanovDev\MaxMessengerBot\Exceptions\ClientApiException;
use BushlanovDev\MaxMessengerBot\Exceptions\NetworkException;
use BushlanovDev\MaxMessengerBot\Exceptions\SerializationException;
use BushlanovDev\MaxMessengerBot\Models\BotInfo;
use BushlanovDev\MaxMessengerBot\Models\Subscription;
use InvalidArgumentException;
/**
* The main entry point for interacting with the Max Bot API.
@@ -15,10 +20,11 @@ use BushlanovDev\MaxMessengerBot\Models\BotInfo;
class Api
{
private const string METHOD_GET = 'GET';
// private const string METHOD_POST = 'POST';
// private const string METHOD_DELETE = 'DELETE';
private const string ACTION_ME = '/me';
private const string ACTION_SUBSCRIPTIONS = '/subscriptions';
private readonly ClientApiInterface $client;
@@ -30,9 +36,14 @@ class Api
* @param string $accessToken Your bot's access token from @MasterBot.
* @param ClientApiInterface|null $client Http api client.
* @param ModelFactory|null $modelFactory
*
* @throws InvalidArgumentException
*/
public function __construct(string $accessToken, ?ClientApiInterface $client = null, ?ModelFactory $modelFactory = null)
{
public function __construct(
string $accessToken,
?ClientApiInterface $client = null,
?ModelFactory $modelFactory = null
) {
$this->client = $client ?? new Client(
$accessToken,
new \GuzzleHttp\Client(),
@@ -43,9 +54,13 @@ class Api
}
/**
* Returns information about the current bot, identified by an access token.
* Information about the current bot, identified by an access token.
*
* @return BotInfo
*
* @throws ClientApiException
* @throws NetworkException
* @throws SerializationException
*/
public function getBotInfo(): BotInfo
{
@@ -53,4 +68,20 @@ class Api
$this->client->request(self::METHOD_GET, self::ACTION_ME)
);
}
/**
* List of all active webhook subscriptions.
*
* @return Subscription[]
*
* @throws ClientApiException
* @throws NetworkException
* @throws SerializationException
*/
public function getSubscriptions(): array
{
return $this->modelFactory->createSubscriptions(
$this->client->request(self::METHOD_GET, self::ACTION_SUBSCRIPTIONS)
);
}
}