1 | <?php |
||
19 | class TgLog |
||
20 | { |
||
21 | /** |
||
22 | * @var RequestHandlerInterface |
||
23 | */ |
||
24 | protected $requestHandler; |
||
25 | |||
26 | /** |
||
27 | * @var PostOptionsConstructor |
||
28 | */ |
||
29 | protected $formConstructor; |
||
30 | |||
31 | /** |
||
32 | * Stores the token |
||
33 | * @var string |
||
34 | */ |
||
35 | private $botToken; |
||
36 | |||
37 | /** |
||
38 | * Contains an instance to a PSR-3 compatible logger |
||
39 | * @var LoggerInterface |
||
40 | */ |
||
41 | protected $logger; |
||
42 | |||
43 | /** |
||
44 | * Stores the API URL from Telegram |
||
45 | * @var string |
||
46 | */ |
||
47 | private $apiUrl; |
||
48 | |||
49 | /** |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $methodName = ''; |
||
53 | |||
54 | /** |
||
55 | * TelegramLog constructor. |
||
56 | * |
||
57 | * @param string $botToken |
||
58 | * @param RequestHandlerInterface $handler |
||
59 | * @param LoggerInterface $logger |
||
60 | */ |
||
61 | 41 | public function __construct(string $botToken, RequestHandlerInterface $handler, LoggerInterface $logger = null) |
|
75 | |||
76 | /** |
||
77 | * Performs the request to the Telegram servers |
||
78 | * |
||
79 | * @param TelegramMethods $method |
||
80 | * |
||
81 | * @return PromiseInterface |
||
82 | * @throws \unreal4u\TelegramAPI\Exceptions\MissingMandatoryField |
||
83 | */ |
||
84 | 32 | public function performApiRequest(TelegramMethods $method): PromiseInterface |
|
97 | |||
98 | /** |
||
99 | * @param File $file |
||
100 | * |
||
101 | * @return PromiseInterface |
||
102 | */ |
||
103 | public function downloadFile(File $file): PromiseInterface |
||
114 | |||
115 | /** |
||
116 | * This is the method that actually makes the call, which can be easily overwritten so that our unit tests can work |
||
117 | * |
||
118 | * @param TelegramMethods $method |
||
119 | * @param array $formData |
||
120 | * |
||
121 | * @return PromiseInterface |
||
122 | */ |
||
123 | protected function sendRequestToTelegram(TelegramMethods $method, array $formData): PromiseInterface |
||
128 | |||
129 | /** |
||
130 | * Resets everything to the default values |
||
131 | * |
||
132 | * @return TgLog |
||
133 | */ |
||
134 | 32 | final protected function resetObjectValues(): TgLog |
|
139 | |||
140 | /** |
||
141 | * Builds up the URL with which we can work with |
||
142 | * |
||
143 | * All methods in the Bot API are case-insensitive. |
||
144 | * All queries must be made using UTF-8. |
||
145 | * |
||
146 | * @see https://core.telegram.org/bots/api#making-requests |
||
147 | * |
||
148 | * @param TelegramMethods $call |
||
149 | * @return string |
||
150 | */ |
||
151 | 31 | protected function composeApiMethodUrl(TelegramMethods $call): string |
|
159 | } |
||
160 |