-
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
addStickerToSet
, deleteStickerFromSet
and `replaceStickerInSe…
…t` methods (#57)
- Loading branch information
Showing
10 changed files
with
381 additions
and
2 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,53 @@ | ||
<?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\RequestFileCollector; | ||
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface; | ||
use Vjik\TelegramBot\Api\Type\Sticker\InputSticker; | ||
|
||
/** | ||
* @see https://core.telegram.org/bots/api#addstickertoset | ||
*/ | ||
final readonly class AddStickerToSet implements TelegramRequestWithResultPreparingInterface | ||
{ | ||
public function __construct( | ||
private int $userId, | ||
private string $name, | ||
private InputSticker $sticker, | ||
) { | ||
} | ||
|
||
public function getHttpMethod(): HttpMethod | ||
{ | ||
return HttpMethod::POST; | ||
} | ||
|
||
public function getApiMethod(): string | ||
{ | ||
return 'addStickerToSet'; | ||
} | ||
|
||
public function getData(): array | ||
{ | ||
$fileCollector = new RequestFileCollector(); | ||
$sticker = $this->sticker->toRequestArray($fileCollector); | ||
|
||
return [ | ||
'user_id' => $this->userId, | ||
'name' => $this->name, | ||
'sticker' => $sticker, | ||
...$fileCollector->get(), | ||
]; | ||
} | ||
|
||
public function prepareResult(mixed $result): true | ||
{ | ||
ValueHelper::assertTrueResult($result); | ||
return $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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?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; | ||
|
||
/** | ||
* @see https://core.telegram.org/bots/api#deletestickerfromset | ||
*/ | ||
final readonly class DeleteStickerFromSet implements TelegramRequestWithResultPreparingInterface | ||
{ | ||
public function __construct( | ||
private string $sticker, | ||
) { | ||
} | ||
|
||
public function getHttpMethod(): HttpMethod | ||
{ | ||
return HttpMethod::POST; | ||
} | ||
|
||
public function getApiMethod(): string | ||
{ | ||
return 'deleteStickerFromSet'; | ||
} | ||
|
||
public function getData(): array | ||
{ | ||
return [ | ||
'sticker' => $this->sticker, | ||
]; | ||
} | ||
|
||
public function prepareResult(mixed $result): true | ||
{ | ||
ValueHelper::assertTrueResult($result); | ||
return $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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?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\RequestFileCollector; | ||
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface; | ||
use Vjik\TelegramBot\Api\Type\Sticker\InputSticker; | ||
|
||
/** | ||
* @see https://core.telegram.org/bots/api#replacestickerinset | ||
*/ | ||
final readonly class ReplaceStickerInSet implements TelegramRequestWithResultPreparingInterface | ||
{ | ||
public function __construct( | ||
private int $userId, | ||
private string $name, | ||
private string $oldSticker, | ||
private InputSticker $sticker, | ||
) { | ||
} | ||
|
||
public function getHttpMethod(): HttpMethod | ||
{ | ||
return HttpMethod::POST; | ||
} | ||
|
||
public function getApiMethod(): string | ||
{ | ||
return 'replaceStickerInSet'; | ||
} | ||
|
||
public function getData(): array | ||
{ | ||
$fileCollector = new RequestFileCollector(); | ||
$sticker = $this->sticker->toRequestArray($fileCollector); | ||
|
||
return [ | ||
'user_id' => $this->userId, | ||
'name' => $this->name, | ||
'old_sticker' => $this->oldSticker, | ||
'sticker' => $sticker, | ||
...$fileCollector->get(), | ||
]; | ||
} | ||
|
||
public function prepareResult(mixed $result): true | ||
{ | ||
ValueHelper::assertTrueResult($result); | ||
return $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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vjik\TelegramBot\Api\Tests\Method\Sticker; | ||
|
||
use HttpSoft\Message\StreamFactory; | ||
use PHPUnit\Framework\TestCase; | ||
use Vjik\TelegramBot\Api\Method\Sticker\AddStickerToSet; | ||
use Vjik\TelegramBot\Api\Request\HttpMethod; | ||
use Vjik\TelegramBot\Api\Type\InputFile; | ||
use Vjik\TelegramBot\Api\Type\Sticker\InputSticker; | ||
|
||
final class AddStickerToSetTest extends TestCase | ||
{ | ||
public function testBase(): void | ||
{ | ||
$file = new InputFile((new StreamFactory())->createStream()); | ||
$inputSticker = new InputSticker($file, 'static', ['😀']); | ||
$method = new AddStickerToSet(1, 'test', $inputSticker); | ||
|
||
$this->assertSame(HttpMethod::POST, $method->getHttpMethod()); | ||
$this->assertSame('addStickerToSet', $method->getApiMethod()); | ||
$this->assertSame( | ||
[ | ||
'user_id' => 1, | ||
'name' => 'test', | ||
'sticker' => [ | ||
'sticker' => 'attach://file0', | ||
'format' => 'static', | ||
'emoji_list' => ['😀'], | ||
], | ||
'file0' => $file, | ||
], | ||
$method->getData(), | ||
); | ||
} | ||
|
||
public function testPrepareResult(): void | ||
{ | ||
$method = new AddStickerToSet( | ||
1, | ||
'test', | ||
new InputSticker('https://example.com/sticker.webp', 'static', ['😀']) | ||
); | ||
|
||
$preparedResult = $method->prepareResult(true); | ||
|
||
$this->assertTrue($preparedResult); | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vjik\TelegramBot\Api\Tests\Method\Sticker; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Vjik\TelegramBot\Api\Method\Sticker\DeleteStickerFromSet; | ||
use Vjik\TelegramBot\Api\Request\HttpMethod; | ||
|
||
final class DeleteStickerFromSetTest extends TestCase | ||
{ | ||
public function testBase(): void | ||
{ | ||
$method = new DeleteStickerFromSet('id'); | ||
|
||
$this->assertSame(HttpMethod::POST, $method->getHttpMethod()); | ||
$this->assertSame('deleteStickerFromSet', $method->getApiMethod()); | ||
$this->assertSame( | ||
[ | ||
'sticker' => 'id', | ||
], | ||
$method->getData(), | ||
); | ||
} | ||
|
||
public function testPrepareResult(): void | ||
{ | ||
$method = new DeleteStickerFromSet('id'); | ||
|
||
$preparedResult = $method->prepareResult(true); | ||
|
||
$this->assertTrue($preparedResult); | ||
} | ||
} |
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,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vjik\TelegramBot\Api\Tests\Method\Sticker; | ||
|
||
use HttpSoft\Message\StreamFactory; | ||
use PHPUnit\Framework\TestCase; | ||
use Vjik\TelegramBot\Api\Method\Sticker\ReplaceStickerInSet; | ||
use Vjik\TelegramBot\Api\Request\HttpMethod; | ||
use Vjik\TelegramBot\Api\Type\InputFile; | ||
use Vjik\TelegramBot\Api\Type\Sticker\InputSticker; | ||
|
||
final class ReplaceStickerInSetTest extends TestCase | ||
{ | ||
public function testBase(): void | ||
{ | ||
$file = new InputFile((new StreamFactory())->createStream()); | ||
$inputSticker = new InputSticker($file, 'static', ['😀']); | ||
$method = new ReplaceStickerInSet(1, 'test', 'oldid', $inputSticker); | ||
|
||
$this->assertSame(HttpMethod::POST, $method->getHttpMethod()); | ||
$this->assertSame('replaceStickerInSet', $method->getApiMethod()); | ||
$this->assertSame( | ||
[ | ||
'user_id' => 1, | ||
'name' => 'test', | ||
'old_sticker' => 'oldid', | ||
'sticker' => [ | ||
'sticker' => 'attach://file0', | ||
'format' => 'static', | ||
'emoji_list' => ['😀'], | ||
], | ||
'file0' => $file, | ||
], | ||
$method->getData(), | ||
); | ||
} | ||
|
||
public function testPrepareResult(): void | ||
{ | ||
$method = new ReplaceStickerInSet( | ||
1, | ||
'test', | ||
'oldid', | ||
new InputSticker('https://example.com/sticker.webp', 'static', ['😀']) | ||
); | ||
|
||
$preparedResult = $method->prepareResult(true); | ||
|
||
$this->assertTrue($preparedResult); | ||
} | ||
} |
Oops, something went wrong.