Move ServerResponse class inside http namespace

parent 3ea4b048
...@@ -45,7 +45,7 @@ class ChatsCommand extends AdminCommand ...@@ -45,7 +45,7 @@ class ChatsCommand extends AdminCommand
/** /**
* Command execute method * Command execute method
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return \Longman\TelegramBot\Http\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
......
...@@ -326,7 +326,7 @@ class CleanupCommand extends AdminCommand ...@@ -326,7 +326,7 @@ class CleanupCommand extends AdminCommand
/** /**
* Execution if MySQL is required but not available * Execution if MySQL is required but not available
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return \Longman\TelegramBot\Http\ServerResponse
*/ */
public function executeNoDb() public function executeNoDb()
{ {
...@@ -345,7 +345,7 @@ class CleanupCommand extends AdminCommand ...@@ -345,7 +345,7 @@ class CleanupCommand extends AdminCommand
/** /**
* Command execute method * Command execute method
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return \Longman\TelegramBot\Http\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
......
...@@ -12,7 +12,7 @@ namespace Longman\TelegramBot\Commands\AdminCommands; ...@@ -12,7 +12,7 @@ namespace Longman\TelegramBot\Commands\AdminCommands;
use Longman\TelegramBot\Commands\AdminCommand; use Longman\TelegramBot\Commands\AdminCommand;
use Longman\TelegramBot\Entities\Message; use Longman\TelegramBot\Entities\Message;
use Longman\TelegramBot\Entities\ServerResponse; use Longman\TelegramBot\Http\ServerResponse;
use Longman\TelegramBot\Http\Request; use Longman\TelegramBot\Http\Request;
/** /**
...@@ -48,7 +48,7 @@ class SendtoallCommand extends AdminCommand ...@@ -48,7 +48,7 @@ class SendtoallCommand extends AdminCommand
/** /**
* Execute command * Execute command
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return \Longman\TelegramBot\Http\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
......
...@@ -54,7 +54,7 @@ class SendtochannelCommand extends AdminCommand ...@@ -54,7 +54,7 @@ class SendtochannelCommand extends AdminCommand
/** /**
* Command execute method * Command execute method
* *
* @return \Longman\TelegramBot\Entities\ServerResponse|mixed * @return \Longman\TelegramBot\Http\ServerResponse|mixed
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
...@@ -275,7 +275,7 @@ class SendtochannelCommand extends AdminCommand ...@@ -275,7 +275,7 @@ class SendtochannelCommand extends AdminCommand
* @param \Longman\TelegramBot\Entities\Message $message * @param \Longman\TelegramBot\Entities\Message $message
* @param array $data * @param array $data
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return \Longman\TelegramBot\Http\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
protected function sendBack(Message $message, array $data) protected function sendBack(Message $message, array $data)
......
...@@ -52,7 +52,7 @@ class WhoisCommand extends AdminCommand ...@@ -52,7 +52,7 @@ class WhoisCommand extends AdminCommand
/** /**
* Command execute method * Command execute method
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return \Longman\TelegramBot\Http\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
......
...@@ -143,7 +143,7 @@ abstract class Command ...@@ -143,7 +143,7 @@ abstract class Command
/** /**
* Pre-execute command * Pre-execute command
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return \Longman\TelegramBot\Http\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function preExecute() public function preExecute()
...@@ -176,7 +176,7 @@ abstract class Command ...@@ -176,7 +176,7 @@ abstract class Command
/** /**
* Execute command * Execute command
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return \Longman\TelegramBot\Http\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
abstract public function execute(); abstract public function execute();
...@@ -184,7 +184,7 @@ abstract class Command ...@@ -184,7 +184,7 @@ abstract class Command
/** /**
* Execution if MySQL is required but not available * Execution if MySQL is required but not available
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return \Longman\TelegramBot\Http\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function executeNoDb() public function executeNoDb()
...@@ -393,7 +393,7 @@ abstract class Command ...@@ -393,7 +393,7 @@ abstract class Command
* @param string $text * @param string $text
* @param array $data * @param array $data
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return \Longman\TelegramBot\Http\ServerResponse
*/ */
public function replyToChat($text, array $data = []) public function replyToChat($text, array $data = [])
{ {
...@@ -413,7 +413,7 @@ abstract class Command ...@@ -413,7 +413,7 @@ abstract class Command
* @param string $text * @param string $text
* @param array $data * @param array $data
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return \Longman\TelegramBot\Http\ServerResponse
*/ */
public function replyToUser($text, array $data = []) public function replyToUser($text, array $data = [])
{ {
......
...@@ -20,7 +20,7 @@ abstract class SystemCommand extends Command ...@@ -20,7 +20,7 @@ abstract class SystemCommand extends Command
* Although system commands should just work and return a successful ServerResponse, * Although system commands should just work and return a successful ServerResponse,
* each system command can override this method to add custom functionality. * each system command can override this method to add custom functionality.
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return \Longman\TelegramBot\Http\ServerResponse
*/ */
public function execute() public function execute()
{ {
......
...@@ -42,7 +42,7 @@ class GenericmessageCommand extends SystemCommand ...@@ -42,7 +42,7 @@ class GenericmessageCommand extends SystemCommand
/** /**
* Execution if MySQL is required but not available * Execution if MySQL is required but not available
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return \Longman\TelegramBot\Http\ServerResponse
*/ */
public function executeNoDb() public function executeNoDb()
{ {
...@@ -53,7 +53,7 @@ class GenericmessageCommand extends SystemCommand ...@@ -53,7 +53,7 @@ class GenericmessageCommand extends SystemCommand
/** /**
* Execute command * Execute command
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return \Longman\TelegramBot\Http\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
......
...@@ -48,7 +48,7 @@ class PreCheckoutQuery extends Entity ...@@ -48,7 +48,7 @@ class PreCheckoutQuery extends Entity
* @param bool $ok * @param bool $ok
* @param array $data * @param array $data
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return \Longman\TelegramBot\Http\ServerResponse
*/ */
public function answer($ok, array $data = []) public function answer($ok, array $data = [])
{ {
......
...@@ -45,7 +45,7 @@ class ShippingQuery extends Entity ...@@ -45,7 +45,7 @@ class ShippingQuery extends Entity
* @param bool $ok * @param bool $ok
* @param array $data * @param array $data
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return \Longman\TelegramBot\Http\ServerResponse
*/ */
public function answer($ok, array $data = []) public function answer($ok, array $data = [])
{ {
......
...@@ -14,7 +14,7 @@ use GuzzleHttp\Client; ...@@ -14,7 +14,7 @@ use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Exception\RequestException;
use Longman\TelegramBot\DB; use Longman\TelegramBot\DB;
use Longman\TelegramBot\Entities\File; use Longman\TelegramBot\Entities\File;
use Longman\TelegramBot\Entities\ServerResponse; use Longman\TelegramBot\Http\ServerResponse;
use Longman\TelegramBot\Exception\TelegramException; use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Telegram; use Longman\TelegramBot\Telegram;
use Longman\TelegramBot\TelegramLog; use Longman\TelegramBot\TelegramLog;
...@@ -504,7 +504,7 @@ class Request ...@@ -504,7 +504,7 @@ class Request
* @param string $action * @param string $action
* @param array $data * @param array $data
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return \Longman\TelegramBot\Http\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function send($action, array $data = []) public static function send($action, array $data = [])
...@@ -589,7 +589,7 @@ class Request ...@@ -589,7 +589,7 @@ class Request
* *
* @param array $data * @param array $data
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return \Longman\TelegramBot\Http\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendMessage(array $data) public static function sendMessage(array $data)
...@@ -614,7 +614,7 @@ class Request ...@@ -614,7 +614,7 @@ class Request
* @param string $action * @param string $action
* @param array $data * @param array $data
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return \Longman\TelegramBot\Http\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function __callStatic($action, array $data) public static function __callStatic($action, array $data)
...@@ -632,7 +632,7 @@ class Request ...@@ -632,7 +632,7 @@ class Request
* No request to telegram are sent, this function is used in commands that * No request to telegram are sent, this function is used in commands that
* don't need to fire a message after execution * don't need to fire a message after execution
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return \Longman\TelegramBot\Http\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function emptyResponse() public static function emptyResponse()
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Longman\TelegramBot\Entities; namespace Longman\TelegramBot\Http;
/** /**
* Class ServerResponse * Class ServerResponse
...@@ -20,7 +20,7 @@ namespace Longman\TelegramBot\Entities; ...@@ -20,7 +20,7 @@ namespace Longman\TelegramBot\Entities;
* *
* @todo method ResponseParameters getParameters() Field which can help to automatically handle the error * @todo method ResponseParameters getParameters() Field which can help to automatically handle the error
*/ */
class ServerResponse extends Entity class ServerResponse
{ {
/** /**
* ServerResponse constructor. * ServerResponse constructor.
...@@ -47,7 +47,30 @@ class ServerResponse extends Entity ...@@ -47,7 +47,30 @@ class ServerResponse extends Entity
} }
} }
parent::__construct($data, $bot_username); //Make sure we're not raw_data inception-ing
if (array_key_exists('raw_data', $data)) {
if ($data['raw_data'] === null) {
unset($data['raw_data']);
}
} else {
$data['raw_data'] = $data;
}
$data['bot_username'] = $bot_username;
$this->assignMemberVariables($data);
}
/**
* Helper to set member variables
*
* @param array $data
*/
protected function assignMemberVariables(array $data)
{
foreach ($data as $key => $value) {
$this->$key = $value;
}
} }
/** /**
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
namespace Longman\TelegramBot\Tests\Unit; namespace Longman\TelegramBot\Tests\Unit;
use Longman\TelegramBot\Entities\Message; use Longman\TelegramBot\Entities\Message;
use Longman\TelegramBot\Entities\ServerResponse; use Longman\TelegramBot\Http\ServerResponse;
use Longman\TelegramBot\Http\Request; use Longman\TelegramBot\Http\Request;
/** /**
......
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