Skip to content

Commit

Permalink
Hide using the BotConfig class (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyTapok-bit committed Jan 13, 2024
1 parent c902e0e commit dac9fb2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ If your project uses multiple bots, you can easily interact with them, just add
```php
<?php

use TgWebValid\BotConfig;

$tgWebValid->addBot(new BotConfig('secondary', 'TELEGRAM_BOT_TOKEN_2'));
$tgWebValid->addBot(new BotConfig('minor', 'TELEGRAM_BOT_TOKEN_3'));
$tgWebValid->addBot('secondary', 'TELEGRAM_BOT_TOKEN_2');
$tgWebValid->addBot('minor', 'TELEGRAM_BOT_TOKEN_3');
```

Getting a bot to work is easy. Specify the name of the bot to work with, or leave the argument empty to get the default bot
Expand Down Expand Up @@ -136,7 +134,6 @@ $loginWidget->authDate;
<?php

use TgWebValid\TgWebValid;
use TgWebValid\BotConfig;
use TgWebValid\Exceptions\BotException;
use TgWebValid\Exceptions\ValidationException;
use Exception;
Expand All @@ -147,8 +144,8 @@ try {
$tgWebValid = new TgWebValid('TELEGRAM_BOT_TOKEN', true);

// Add bots only when needed
$tgWebValid->addBot(new BotConfig('secondary', 'TELEGRAM_BOT_TOKEN_2'));
$tgWebValid->addBot(new BotConfig('minor', 'TELEGRAM_BOT_TOKEN_3'));
$tgWebValid->addBot('secondary', 'TELEGRAM_BOT_TOKEN_2');
$tgWebValid->addBot('minor', 'TELEGRAM_BOT_TOKEN_3');

$initData = $tgWebValid->bot()->validateInitData('query_id=...');

Expand Down
4 changes: 2 additions & 2 deletions src/TgWebValid.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public function __construct(
{
}

public function addBot(BotConfig $bot): void
public function addBot(string $name, string $token): void
{
$this->bots[$bot->name] = $bot;
$this->bots[$name] = new BotConfig($name, $token);
}

public function bot(?string $name = null): Bot
Expand Down
5 changes: 2 additions & 3 deletions tests/TgWebValidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PHPUnit\Framework\TestCase;
use TgWebValid\Bot;
use TgWebValid\BotConfig;
use TgWebValid\Exceptions\BotException;
use TgWebValid\TgWebValid;

Expand All @@ -15,8 +14,8 @@ class TgWebValidTest extends TestCase
public function setUp(): void
{
$this->manager = new TgWebValid('DEFAULT_BOT_TOKEN');
$this->manager->addBot(new BotConfig('next', 'NEXT_BOT_TOKEN'));
$this->manager->addBot(new BotConfig('other', 'OTHER_BOT_TOKEN'));
$this->manager->addBot('next', 'NEXT_BOT_TOKEN');
$this->manager->addBot('other', 'OTHER_BOT_TOKEN');
}

public function testWithoutName(): void
Expand Down

0 comments on commit dac9fb2

Please sign in to comment.