Commit 3dd1b671 authored by Jack'lul's avatar Jack'lul

implement responses for API 2.1

parent cbc9dd05
...@@ -14,32 +14,42 @@ use Longman\TelegramBot\Exception\TelegramException; ...@@ -14,32 +14,42 @@ use Longman\TelegramBot\Exception\TelegramException;
class ServerResponse extends Entity class ServerResponse extends Entity
{ {
protected $ok; protected $ok;
protected $result; protected $result;
protected $error_code; protected $error_code;
protected $description; protected $description;
public function __construct(array $data, $bot_name) public function __construct(array $data, $bot_name)
{ {
if (isset($data['ok']) & isset($data['result'])) { if (isset($data['ok']) & isset($data['result'])) {
if (is_array($data['result'])) { if (is_array($data['result'])) {
if ($data['ok'] & !$this->isAssoc($data['result'])) { if ($data['ok'] & !$this->isAssoc($data['result']) & !isset($data['result'][0]['user'])) {
//get update //Get Update
foreach ($data['result'] as $update) { foreach ($data['result'] as $update) {
$this->result[] = new Update($update, $bot_name); $this->result[] = new Update($update, $bot_name);
} }
} elseif ($data['ok'] & !$this->isAssoc($data['result']) & isset($data['result'][0]['user'])) {
//Response from getChatAdministrators
$this->result = [];
foreach ($data['result'] as $user) {
array_push($this->result, new ChatMember($user));
}
} elseif ($data['ok'] & $this->isAssoc($data['result'])) { } elseif ($data['ok'] & $this->isAssoc($data['result'])) {
if (isset($data['result']['total_count'])) { if (isset($data['result']['total_count'])) {
//getUserProfilePhotos //Response from getUserProfilePhotos
$this->result = new UserProfilePhotos($data['result']); $this->result = new UserProfilePhotos($data['result']);
} elseif (isset($data['result']['file_id'])) { } elseif (isset($data['result']['file_id'])) {
//Response getFile //Response from getFile
$this->result = new File($data['result']); $this->result = new File($data['result']);
} elseif (isset($data['result']['username'])) { } elseif (isset($data['result']['username'])) {
//Response getMe //Response from getMe
$this->result = new User($data['result']); $this->result = new User($data['result']);
} elseif (isset($data['result']['id'])) {
//Response from getChat
$this->result = new Chat($data['result']);
} elseif (isset($data['result']['user'])) {
//Response from getChatMember
$this->result = new ChatMember($data['result']);
} else { } else {
//Response from sendMessage //Response from sendMessage
$this->result = new Message($data['result'], $bot_name); $this->result = new Message($data['result'], $bot_name);
...@@ -50,7 +60,7 @@ class ServerResponse extends Entity ...@@ -50,7 +60,7 @@ class ServerResponse extends Entity
$this->error_code = null; $this->error_code = null;
$this->description = null; $this->description = null;
} else { } else {
if ($data['ok'] & $data['result'] == true) { if ($data['ok'] & $data['result'] === true) {
//Response from setWebhook set //Response from setWebhook set
$this->ok = $data['ok']; $this->ok = $data['ok'];
$this->result = true; $this->result = true;
...@@ -61,6 +71,9 @@ class ServerResponse extends Entity ...@@ -61,6 +71,9 @@ class ServerResponse extends Entity
} else { } else {
$this->description = ''; $this->description = '';
} }
} elseif (is_numeric($data['result'])) {
//Response from getChatMembersCount
$this->result = $data['result'];
} else { } else {
$this->ok = false; $this->ok = false;
$this->result = null; $this->result = null;
......
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