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
+29
View File
@@ -6,6 +6,7 @@ namespace BushlanovDev\MaxMessengerBot;
use BushlanovDev\MaxMessengerBot\Models\BotCommand;
use BushlanovDev\MaxMessengerBot\Models\BotInfo;
use BushlanovDev\MaxMessengerBot\Models\Subscription;
/**
* Creates DTOs from raw associative arrays returned by the API client.
@@ -13,6 +14,8 @@ use BushlanovDev\MaxMessengerBot\Models\BotInfo;
class ModelFactory
{
/**
* Information about the current bot.
*
* @param array<string, mixed> $data
*
* @return BotInfo
@@ -24,4 +27,30 @@ class ModelFactory
return BotInfo::fromArray($data);
}
/**
* Information about webhook subscription.
*
* @param array<string, mixed> $data
*
* @return Subscription
*/
public function createSubscription(array $data): Subscription
{
return Subscription::fromArray($data);
}
/**
* List of all active webhook subscriptions.
*
* @param array<string, mixed> $data
*
* @return Subscription[]
*/
public function createSubscriptions(array $data): array
{
return isset($data['subscriptions']) && is_array($data['subscriptions'])
? array_map([$this, 'createSubscription'], $data['subscriptions'])
: [];
}
}