@@ -109,17 +109,8 @@ public static function generateGeneralFakeServerSesponse($data = null)
109
109
return $ fake_response ;
110
110
}
111
111
112
- public static function send ( $ action , array $ data = null )
112
+ public static function executeCurl ( i $ action , array $ data )
113
113
{
114
- if (!in_array ($ action , self ::$ methods )) {
115
- throw new TelegramException ('This methods doesn \'t exist! ' );
116
- }
117
-
118
- if (defined ('PHPUNIT_TESTSUITE ' )) {
119
- $ fake_response = self ::generateGeneralFakeServerSesponse ($ data );
120
- return new ServerResponse ($ fake_response , self ::$ telegram ->getBotName ());
121
- }
122
-
123
114
124
115
$ ch = curl_init ();
125
116
if ($ ch === false ) {
@@ -146,6 +137,21 @@ public static function send($action, array $data = null)
146
137
throw new TelegramException (curl_error ($ ch ), curl_errno ($ ch ));
147
138
}
148
139
curl_close ($ ch );
140
+ return $ result ;
141
+ }
142
+
143
+ public static function send ($ action , array $ data = null )
144
+ {
145
+ if (!in_array ($ action , self ::$ methods )) {
146
+ throw new TelegramException ('This methods doesn \'t exist! ' );
147
+ }
148
+
149
+ if (defined ('PHPUNIT_TESTSUITE ' )) {
150
+ $ fake_response = self ::generateGeneralFakeServerSesponse ($ data );
151
+ return new ServerResponse ($ fake_response , self ::$ telegram ->getBotName ());
152
+ }
153
+
154
+ $ result = self ::executeCurl ($ action , $ data );
149
155
150
156
if (empty ($ result )) {
151
157
$ response ['ok ' ] = 1 ;
@@ -154,7 +160,7 @@ public static function send($action, array $data = null)
154
160
$ result =json_encode ($ response );
155
161
}
156
162
//For the getUpdate method log
157
- self ::setInputRaw ($ result );
163
+ // self::setInputRaw($result);
158
164
159
165
$ bot_name = self ::$ telegram ->getBotName ();
160
166
return new ServerResponse (json_decode ($ result , true ), $ bot_name );
@@ -211,15 +217,28 @@ public static function sendChatAction(array $data)
211
217
212
218
public static function getUpdates ($ data )
213
219
{
220
+
214
221
if ($ update = self ::$ telegram ->getCustomUpdate ()) {
215
- //Cannot be used for testing yet json update have to be converted in a ServerResponse Object
216
- self ::$ input = $ update ;
222
+ self ::setInputRaw ($ update );
217
223
} else {
218
- self ::$ input = self ::send ('getUpdates ' , $ data );
224
+
225
+ $ result = self ::executeCurl ('getUpdates ' , $ data );
226
+
227
+ if (empty ($ result )) {
228
+ $ response ['ok ' ] = 1 ;
229
+ $ response ['error_code ' ] = 1 ;
230
+ $ response ['description ' ] = 'Empty server response ' ;
231
+ $ result =json_encode ($ response );
232
+ }
233
+ self ::setInputRaw ($ result );
234
+
219
235
}
220
- //In send methods is set input_raw
236
+
221
237
self ::log ();
222
- return self ::$ input ;
238
+
239
+ $ bot_name = self ::$ telegram ->getBotName ();
240
+ return new ServerResponse (json_decode ($ result , true ), $ bot_name );
241
+
223
242
}
224
243
225
244
public static function setWebhook ($ url )
0 commit comments