Old request class renamed to Client

parent 404efd8e
......@@ -13,7 +13,7 @@ namespace Longman\TelegramBot\Commands\AdminCommands;
use Longman\TelegramBot\Commands\AdminCommand;
use Longman\TelegramBot\DB;
use Longman\TelegramBot\Entities\Chat;
use Longman\TelegramBot\Http\Request;
use Longman\TelegramBot\Http\Client;
class ChatsCommand extends AdminCommand
{
......@@ -135,6 +135,6 @@ class ChatsCommand extends AdminCommand
'text' => $text_back,
];
return Request::sendMessage($data);
return Client::sendMessage($data);
}
}
......@@ -13,7 +13,7 @@ namespace Longman\TelegramBot\Commands\AdminCommands;
use Longman\TelegramBot\Commands\AdminCommand;
use Longman\TelegramBot\DB;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Http\Request;
use Longman\TelegramBot\Http\Client;
use Longman\TelegramBot\TelegramLog;
use PDOException;
......@@ -339,7 +339,7 @@ class CleanupCommand extends AdminCommand
'text' => '*No database connection!*',
];
return Request::sendMessage($data);
return Client::sendMessage($data);
}
/**
......@@ -375,7 +375,7 @@ class CleanupCommand extends AdminCommand
$data['text'] = 'Cleaning up tables:' . PHP_EOL . implode(PHP_EOL, $infos);
Request::sendMessage($data);
Client::sendMessage($data);
$rows = 0;
$pdo = DB::getPdo();
......@@ -395,7 +395,7 @@ class CleanupCommand extends AdminCommand
$pdo->rollBack(); // rollback changes on exception (useful if you want to track down error - you can't replicate it when some of the data is already deleted...)
$data['text'] = '*Database cleanup failed!* _(check your error logs)_';
Request::sendMessage($data);
Client::sendMessage($data);
throw new TelegramException($e->getMessage());
}
......@@ -406,6 +406,6 @@ class CleanupCommand extends AdminCommand
$data['text'] = '*No data to clean!*';
}
return Request::sendMessage($data);
return Client::sendMessage($data);
}
}
......@@ -12,7 +12,7 @@ namespace Longman\TelegramBot\Commands\AdminCommands;
use Longman\TelegramBot\Commands\AdminCommand;
use Longman\TelegramBot\DB;
use Longman\TelegramBot\Http\Request;
use Longman\TelegramBot\Http\Client;
/**
* Admin "/debug" command
......@@ -57,7 +57,7 @@ class DebugCommand extends AdminCommand
if ($text !== 'glasnost' && ! $chat->isPrivateChat()) {
$data['text'] = 'Only available in a private chat.';
return Request::sendMessage($data);
return Client::sendMessage($data);
}
$debug_info = [];
......@@ -95,10 +95,10 @@ class DebugCommand extends AdminCommand
$webhook_info_title = '*Webhook Info:*';
try {
// Check if we're actually using the Webhook method.
if (Request::getInput() === '') {
if (Client::getInput() === '') {
$debug_info[] = $webhook_info_title . ' `Using getUpdates method, not Webhook.`';
} else {
$webhook_info_result = json_decode(Request::getWebhookInfo(), true)['result'];
$webhook_info_result = json_decode(Client::getWebhookInfo(), true)['result'];
// Add a human-readable error date string if necessary.
if (isset($webhook_info_result['last_error_date'])) {
$webhook_info_result['last_error_date_string'] = date('Y-m-d H:i:s', $webhook_info_result['last_error_date']);
......@@ -118,6 +118,6 @@ class DebugCommand extends AdminCommand
$data['parse_mode'] = 'Markdown';
$data['text'] = implode(PHP_EOL, $debug_info);
return Request::sendMessage($data);
return Client::sendMessage($data);
}
}
......@@ -13,7 +13,7 @@ namespace Longman\TelegramBot\Commands\AdminCommands;
use Longman\TelegramBot\Commands\AdminCommand;
use Longman\TelegramBot\Entities\Message;
use Longman\TelegramBot\Http\ServerResponse;
use Longman\TelegramBot\Http\Request;
use Longman\TelegramBot\Http\Client;
/**
* Admin "/sendtoall" command
......@@ -60,7 +60,7 @@ class SendtoallCommand extends AdminCommand
}
/** @var ServerResponse[] $results */
$results = Request::sendToActiveChats(
$results = Client::sendToActiveChats(
'sendMessage', //callback function to execute (see Request.php methods)
['text' => $text], //Param to evaluate the request
[
......
......@@ -15,7 +15,7 @@ use Longman\TelegramBot\Conversation;
use Longman\TelegramBot\Entities\Chat;
use Longman\TelegramBot\Entities\Keyboard;
use Longman\TelegramBot\Entities\Message;
use Longman\TelegramBot\Http\Request;
use Longman\TelegramBot\Http\Client;
class SendtochannelCommand extends AdminCommand
{
......@@ -232,7 +232,7 @@ class SendtochannelCommand extends AdminCommand
if (! $text_yes_or_no && $notes['last_message_id'] !== $message->getMessageId()) {
$data['text'] .= PHP_EOL . 'Type Yes or No';
}
$result = Request::sendMessage($data);
$result = Client::sendMessage($data);
}
break;
}
......@@ -255,7 +255,7 @@ class SendtochannelCommand extends AdminCommand
}
$this->conversation->stop();
$result = Request::sendMessage($data);
$result = Client::sendMessage($data);
}
return $result;
......@@ -305,7 +305,7 @@ class SendtochannelCommand extends AdminCommand
$data['longitude'] = $message->getLocation()->getLongitude();
}
return Request::send('send' . ucfirst($type), $data);
return Client::send('send' . ucfirst($type), $data);
}
/**
......
......@@ -17,7 +17,7 @@ use Longman\TelegramBot\DB;
use Longman\TelegramBot\Entities\Chat;
use Longman\TelegramBot\Entities\PhotoSize;
use Longman\TelegramBot\Entities\UserProfilePhotos;
use Longman\TelegramBot\Http\Request;
use Longman\TelegramBot\Http\Client;
/**
* Admin "/whois" command
......@@ -141,7 +141,7 @@ class WhoisCommand extends AdminCommand
//Code from Whoami command
$limit = 10;
$offset = null;
$response = Request::getUserProfilePhotos(
$response = Client::getUserProfilePhotos(
[
'user_id' => $user_id,
'limit' => $limit,
......@@ -163,7 +163,7 @@ class WhoisCommand extends AdminCommand
$data['photo'] = $file_id;
$data['caption'] = $text;
return Request::sendPhoto($data);
return Client::sendPhoto($data);
}
}
} elseif ($chat->isGroupChat()) {
......@@ -182,6 +182,6 @@ class WhoisCommand extends AdminCommand
$data['text'] = $text;
return Request::sendMessage($data);
return Client::sendMessage($data);
}
}
......@@ -16,7 +16,7 @@ use Longman\TelegramBot\Entities\ChosenInlineResult;
use Longman\TelegramBot\Entities\InlineQuery;
use Longman\TelegramBot\Entities\Message;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Http\Request;
use Longman\TelegramBot\Http\Client;
use Longman\TelegramBot\Telegram;
/**
......@@ -156,7 +156,7 @@ abstract class Command
$message = $this->getMessage();
if ($user = $message->getFrom()) {
return Request::sendMessage([
return Client::sendMessage([
'chat_id' => $user->getId(),
'parse_mode' => 'Markdown',
'text' => sprintf(
......@@ -167,7 +167,7 @@ abstract class Command
]);
}
return Request::emptyResponse();
return Client::emptyResponse();
}
return $this->execute();
......@@ -198,7 +198,7 @@ abstract class Command
'text' => 'Sorry no database connection, unable to execute "' . $this->name . '" command.',
];
return Request::sendMessage($data);
return Client::sendMessage($data);
}
/**
......@@ -375,7 +375,7 @@ abstract class Command
if (!$chat->isPrivateChat()) {
// Delete the falsely called command message.
Request::deleteMessage([
Client::deleteMessage([
'chat_id' => $chat->getId(),
'message_id' => $message->getMessageId(),
]);
......@@ -398,13 +398,13 @@ abstract class Command
public function replyToChat($text, array $data = [])
{
if ($message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost()) {
return Request::sendMessage(array_merge([
return Client::sendMessage(array_merge([
'chat_id' => $message->getChat()->getId(),
'text' => $text,
], $data));
}
return Request::emptyResponse();
return Client::emptyResponse();
}
/**
......@@ -418,12 +418,12 @@ abstract class Command
public function replyToUser($text, array $data = [])
{
if ($message = $this->getMessage() ?: $this->getEditedMessage()) {
return Request::sendMessage(array_merge([
return Client::sendMessage(array_merge([
'chat_id' => $message->getFrom()->getId(),
'text' => $text,
], $data));
}
return Request::emptyResponse();
return Client::emptyResponse();
}
}
......@@ -10,7 +10,7 @@
namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Http\Request;
use Longman\TelegramBot\Http\Client;
abstract class SystemCommand extends Command
{
......@@ -25,6 +25,6 @@ abstract class SystemCommand extends Command
public function execute()
{
//System command, return empty ServerResponse by default
return Request::emptyResponse();
return Client::emptyResponse();
}
}
......@@ -11,7 +11,7 @@
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Http\Request;
use Longman\TelegramBot\Http\Client;
/**
* Callback query command
......@@ -56,7 +56,7 @@ class CallbackqueryCommand extends SystemCommand
$callback($this->getUpdate()->getCallbackQuery());
}
return Request::answerCallbackQuery(['callback_query_id' => $this->getUpdate()->getCallbackQuery()->getId()]);
return Client::answerCallbackQuery(['callback_query_id' => $this->getUpdate()->getCallbackQuery()->getId()]);
}
/**
......
......@@ -12,7 +12,7 @@ namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Conversation;
use Longman\TelegramBot\Http\Request;
use Longman\TelegramBot\Http\Client;
/**
* Generic message command
......@@ -47,7 +47,7 @@ class GenericmessageCommand extends SystemCommand
public function executeNoDb()
{
//Do nothing
return Request::emptyResponse();
return Client::emptyResponse();
}
/**
......@@ -69,6 +69,6 @@ class GenericmessageCommand extends SystemCommand
return $this->telegram->executeCommand($command);
}
return Request::emptyResponse();
return Client::emptyResponse();
}
}
......@@ -11,7 +11,7 @@
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Http\Request;
use Longman\TelegramBot\Http\Client;
/**
* Inline query command
......@@ -45,6 +45,6 @@ class InlinequeryCommand extends SystemCommand
//$user_id = $inline_query->getFrom()->getId();
//$query = $inline_query->getQuery();
return Request::answerInlineQuery(['inline_query_id' => $this->getUpdate()->getInlineQuery()->getId()]);
return Client::answerInlineQuery(['inline_query_id' => $this->getUpdate()->getInlineQuery()->getId()]);
}
}
......@@ -10,7 +10,7 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Http\Request;
use Longman\TelegramBot\Http\Client;
/**
* Class CallbackQuery.
......@@ -46,7 +46,7 @@ class CallbackQuery extends Entity
*/
public function answer(array $data = [])
{
return Request::answerCallbackQuery(array_merge([
return Client::answerCallbackQuery(array_merge([
'callback_query_id' => $this->getId(),
], $data));
}
......
......@@ -11,7 +11,7 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Entities\InlineQuery\InlineQueryResult;
use Longman\TelegramBot\Http\Request;
use Longman\TelegramBot\Http\Client;
/**
* Class InlineQuery
......@@ -47,7 +47,7 @@ class InlineQuery extends Entity
*/
public function answer(array $results, array $data = [])
{
return Request::answerCallbackQuery(array_merge([
return Client::answerCallbackQuery(array_merge([
'callback_query_id' => $this->getId(),
'results' => $results,
], $data));
......
......@@ -12,7 +12,7 @@ namespace Longman\TelegramBot\Entities\Payments;
use Longman\TelegramBot\Entities\Entity;
use Longman\TelegramBot\Entities\User;
use Longman\TelegramBot\Http\Request;
use Longman\TelegramBot\Http\Client;
/**
* Class PreCheckoutQuery
......@@ -52,7 +52,7 @@ class PreCheckoutQuery extends Entity
*/
public function answer($ok, array $data = [])
{
return Request::answerPreCheckoutQuery(array_merge([
return Client::answerPreCheckoutQuery(array_merge([
'pre_checkout_query_id' => $this->getId(),
'ok' => $ok,
], $data));
......
......@@ -12,7 +12,7 @@ namespace Longman\TelegramBot\Entities\Payments;
use Longman\TelegramBot\Entities\Entity;
use Longman\TelegramBot\Entities\User;
use Longman\TelegramBot\Http\Request;
use Longman\TelegramBot\Http\Client;
/**
* Class ShippingQuery
......@@ -49,7 +49,7 @@ class ShippingQuery extends Entity
*/
public function answer($ok, array $data = [])
{
return Request::answerShippingQuery(array_merge([
return Client::answerShippingQuery(array_merge([
'shipping_query_id' => $this->getId(),
'ok' => $ok,
], $data));
......
This diff is collapsed.
......@@ -11,7 +11,7 @@
namespace Longman\TelegramBot\Commands\UserCommands;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Http\Request;
use Longman\TelegramBot\Http\Client;
/**
* Test "/hidden" command to test $show_in_help
......@@ -51,6 +51,6 @@ class HiddenCommand extends UserCommand
*/
public function execute()
{
return Request::emptyResponse();
return Client::emptyResponse();
}
}
......@@ -11,7 +11,7 @@
namespace Longman\TelegramBot\Commands\UserCommands;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Http\Request;
use Longman\TelegramBot\Http\Client;
/**
* Test "/visible" command to test $show_in_help
......@@ -51,6 +51,6 @@ class VisibleCommand extends UserCommand
*/
public function execute()
{
return Request::emptyResponse();
return Client::emptyResponse();
}
}
......@@ -14,7 +14,7 @@ namespace Longman\TelegramBot\Tests\Unit;
use Longman\TelegramBot\Entities\Message;
use Longman\TelegramBot\Http\ServerResponse;
use Longman\TelegramBot\Http\Request;
use Longman\TelegramBot\Http\Client;
/**
* @package TelegramTest
......@@ -259,7 +259,7 @@ class ServerResponseTest extends TestCase
public function testSetGeneralTestFakeResponse()
{
//setWebhook ok
$fake_response = Request::generateGeneralFakeServerResponse();
$fake_response = Client::generateGeneralFakeServerResponse();
$server = new ServerResponse($fake_response, 'testbot');
......@@ -269,7 +269,7 @@ class ServerResponseTest extends TestCase
self::assertEquals('', $server->getDescription());
//sendMessage ok
$fake_response = Request::generateGeneralFakeServerResponse(['chat_id' => 123456789, 'text' => 'hello']);
$fake_response = Client::generateGeneralFakeServerResponse(['chat_id' => 123456789, 'text' => 'hello']);
$server = new ServerResponse($fake_response, 'testbot');
......
......@@ -151,4 +151,13 @@ class TelegramTest extends TestCase
$this->assertInstanceOf(\Illuminate\Container\Container::class, $telegram);
}
public function testCustom()
{
$telegram = new Telegram(self::$dummy_api_key, 'testbot');
$telegram->handle();
$this->assertTrue(true);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment