-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
getCustomEmojiStickers
method (#54)
- Loading branch information
Showing
7 changed files
with
151 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vjik\TelegramBot\Api\Method\Sticker; | ||
|
||
use Vjik\TelegramBot\Api\ParseResult\ValueHelper; | ||
use Vjik\TelegramBot\Api\Request\HttpMethod; | ||
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface; | ||
use Vjik\TelegramBot\Api\Type\Sticker\Sticker; | ||
|
||
/** | ||
* @see https://core.telegram.org/bots/api#getcustomemojistickers | ||
*/ | ||
final readonly class GetCustomEmojiStickers implements TelegramRequestWithResultPreparingInterface | ||
{ | ||
/** | ||
* @param string[] $customEmojiIds | ||
*/ | ||
public function __construct( | ||
private array $customEmojiIds, | ||
) { | ||
} | ||
|
||
public function getHttpMethod(): HttpMethod | ||
{ | ||
return HttpMethod::GET; | ||
} | ||
|
||
public function getApiMethod(): string | ||
{ | ||
return 'getCustomEmojiStickers'; | ||
} | ||
|
||
public function getData(): array | ||
{ | ||
return [ | ||
'custom_emoji_ids' => $this->customEmojiIds, | ||
]; | ||
} | ||
|
||
/** | ||
* @return Sticker[] | ||
*/ | ||
public function prepareResult(mixed $result): array | ||
{ | ||
ValueHelper::assertArrayResult($result); | ||
return ValueHelper::getArrayOfStickers($result); | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vjik\TelegramBot\Api\Tests\Method\Sticker; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Vjik\TelegramBot\Api\Method\Sticker\GetCustomEmojiStickers; | ||
use Vjik\TelegramBot\Api\Request\HttpMethod; | ||
use Vjik\TelegramBot\Api\Type\Sticker\Sticker; | ||
|
||
final class GetCustomEmojiStickersTest extends TestCase | ||
{ | ||
public function testBase(): void | ||
{ | ||
$method = new GetCustomEmojiStickers(['id1']); | ||
|
||
$this->assertSame(HttpMethod::GET, $method->getHttpMethod()); | ||
$this->assertSame('getCustomEmojiStickers', $method->getApiMethod()); | ||
$this->assertSame( | ||
[ | ||
'custom_emoji_ids' => ['id1'], | ||
], | ||
$method->getData(), | ||
); | ||
} | ||
|
||
public function testPrepareResult(): void | ||
{ | ||
$method = new GetCustomEmojiStickers(['id1']); | ||
|
||
$preparedResult = $method->prepareResult([ | ||
[ | ||
'file_id' => 'x1', | ||
'file_unique_id' => 'fullX1', | ||
'type' => 'regular', | ||
'width' => 100, | ||
'height' => 120, | ||
'is_animated' => false, | ||
'is_video' => true, | ||
], | ||
]); | ||
|
||
$this->assertIsArray($preparedResult); | ||
$this->assertCount(1, $preparedResult); | ||
$this->assertInstanceOf(Sticker::class, $preparedResult[0]); | ||
$this->assertSame('x1', $preparedResult[0]->fileId); | ||
} | ||
} |
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