@@ -665,9 +665,9 @@ protected function _oauth2TokenCurl()
665
665
$ this ->_validateSslCertificate ($ validation_result );
666
666
667
667
$ httpstatus = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
668
- $ reply = $ this ->_parseApiReply ($ result );
669
- $ headers = $ this ->_parseApiReply ($ result , true );
670
- $ rate = $ this ->_getRateLimitInfo ($ headers );
668
+ list ( $ headers , $ reply) = $ this ->_parseApiHeaders ($ result );
669
+ $ reply = $ this ->_parseApiReply ($ reply );
670
+ $ rate = $ this ->_getRateLimitInfo ($ headers );
671
671
switch ($ this ->_return_format ) {
672
672
case CODEBIRD_RETURNFORMAT_ARRAY :
673
673
$ reply ['httpstatus ' ] = $ httpstatus ;
@@ -745,9 +745,9 @@ protected function _oauth2TokenNoCurl()
745
745
$ httpstatus = $ match [1 ];
746
746
}
747
747
748
- $ reply = $ this ->_parseApiReply ($ result );
749
- $ headers = $ this ->_parseApiReply ($ result , true );
750
- $ rate = $ this ->_getRateLimitInfo ($ headers );
748
+ list ( $ headers , $ reply) = $ this ->_parseApiHeaders ($ result );
749
+ $ reply = $ this ->_parseApiReply ($ reply );
750
+ $ rate = $ this ->_getRateLimitInfo ($ headers );
751
751
switch ($ this ->_return_format ) {
752
752
case CODEBIRD_RETURNFORMAT_ARRAY :
753
753
$ reply ['httpstatus ' ] = $ httpstatus ;
@@ -1427,9 +1427,9 @@ protected function _callApiNoCurl($httpmethod, $method, $params = array(), $mult
1427
1427
$ httpstatus = $ match [1 ];
1428
1428
}
1429
1429
1430
- $ reply = $ this ->_parseApiReply ($ result );
1431
- $ headers = $ this ->_parseApiReply ($ result , true );
1432
- $ rate = $ this ->_getRateLimitInfo ($ headers );
1430
+ list ( $ headers , $ reply) = $ this ->_parseApiHeaders ($ result );
1431
+ $ reply = $ this ->_parseApiReply ($ reply );
1432
+ $ rate = $ this ->_getRateLimitInfo ($ headers );
1433
1433
switch ($ this ->_return_format ) {
1434
1434
case CODEBIRD_RETURNFORMAT_ARRAY :
1435
1435
$ reply ['httpstatus ' ] = $ httpstatus ;
@@ -1444,15 +1444,13 @@ protected function _callApiNoCurl($httpmethod, $method, $params = array(), $mult
1444
1444
}
1445
1445
1446
1446
/**
1447
- * Parses the API reply to encode it in the set return_format
1447
+ * Parses the API reply to separate headers from the body
1448
1448
*
1449
- * @param string $reply The actual reply, JSON-encoded or URL-encoded
1450
- * @param bool $get_headers If to return the headers instead of body
1449
+ * @param string $reply The actual raw HTTP request reply
1451
1450
*
1452
- * @return array|object The parsed reply
1451
+ * @return array (headers, reply)
1453
1452
*/
1454
- protected function _parseApiReply ($ reply , $ get_headers = false )
1455
- {
1453
+ protected function _parseApiHeaders ($ reply ) {
1456
1454
// split headers and body
1457
1455
$ headers = array ();
1458
1456
$ reply = explode ("\r\n\r\n" , $ reply , 4 );
@@ -1481,15 +1479,25 @@ protected function _parseApiReply($reply, $get_headers = false)
1481
1479
}
1482
1480
$ headers [$ key ] = $ value ;
1483
1481
}
1484
- if ($ get_headers ) {
1485
- return $ headers ;
1486
- }
1482
+
1487
1483
if (count ($ reply ) > 1 ) {
1488
1484
$ reply = $ reply [1 ];
1489
1485
} else {
1490
1486
$ reply = '' ;
1491
1487
}
1492
1488
1489
+ return array ($ headers , $ reply );
1490
+ }
1491
+
1492
+ /**
1493
+ * Parses the API reply to encode it in the set return_format
1494
+ *
1495
+ * @param string $reply The actual HTTP body, JSON-encoded or URL-encoded
1496
+ *
1497
+ * @return array|object The parsed reply
1498
+ */
1499
+ protected function _parseApiReply ($ reply )
1500
+ {
1493
1501
$ need_array = $ this ->_return_format === CODEBIRD_RETURNFORMAT_ARRAY ;
1494
1502
if ($ reply === '[] ' ) {
1495
1503
switch ($ this ->_return_format ) {
0 commit comments