@@ -1312,18 +1312,22 @@ protected function _parseBearerReply($result, $httpstatus)
1312
1312
*
1313
1313
* @param array $headers The CURL response headers
1314
1314
*
1315
- * @return null|array The rate-limiting information
1315
+ * @return null|array|object The rate-limiting information
1316
1316
*/
1317
1317
protected function _getRateLimitInfo ($ headers )
1318
1318
{
1319
1319
if (! isset ($ headers ['x-rate-limit-limit ' ])) {
1320
1320
return null ;
1321
1321
}
1322
- return [
1322
+ $ rate = [
1323
1323
'limit ' => $ headers ['x-rate-limit-limit ' ],
1324
1324
'remaining ' => $ headers ['x-rate-limit-remaining ' ],
1325
1325
'reset ' => $ headers ['x-rate-limit-reset ' ]
1326
1326
];
1327
+ if ($ this ->_return_format === CODEBIRD_RETURNFORMAT_OBJECT ) {
1328
+ return (object ) $ rate ;
1329
+ }
1330
+ return $ rate ;
1327
1331
}
1328
1332
1329
1333
/**
@@ -1698,7 +1702,7 @@ protected function _getMultipartRequestFromParams($method_template, $border, $pa
1698
1702
*
1699
1703
* @param string $method_template The method template to call
1700
1704
* @param string $key The parameter name
1701
- * @param array $value The possible file name or URL
1705
+ * @param string $value The possible file name or URL
1702
1706
*
1703
1707
* @return mixed
1704
1708
*/
@@ -2034,16 +2038,7 @@ protected function _callApiCurl(
2034
2038
$ reply = $ this ->_parseApiReply ($ reply );
2035
2039
$ rate = $ this ->_getRateLimitInfo ($ headers );
2036
2040
2037
- switch ($ this ->_return_format ) {
2038
- case CODEBIRD_RETURNFORMAT_ARRAY :
2039
- $ reply ['httpstatus ' ] = $ httpstatus ;
2040
- $ reply ['rate ' ] = $ rate ;
2041
- break ;
2042
- case CODEBIRD_RETURNFORMAT_OBJECT :
2043
- $ reply ->httpstatus = $ httpstatus ;
2044
- $ reply ->rate = $ rate ;
2045
- break ;
2046
- }
2041
+ $ reply = $ this ->_appendHttpStatusAndRate ($ reply , $ httpstatus , $ rate );
2047
2042
return $ reply ;
2048
2043
}
2049
2044
@@ -2111,16 +2106,8 @@ protected function _callApiNoCurl(
2111
2106
$ reply = $ this ->_parseApiReplyPrefillHeaders ($ headers , $ reply );
2112
2107
$ reply = $ this ->_parseApiReply ($ reply );
2113
2108
$ rate = $ this ->_getRateLimitInfo ($ headers );
2114
- switch ($ this ->_return_format ) {
2115
- case CODEBIRD_RETURNFORMAT_ARRAY :
2116
- $ reply ['httpstatus ' ] = $ httpstatus ;
2117
- $ reply ['rate ' ] = $ rate ;
2118
- break ;
2119
- case CODEBIRD_RETURNFORMAT_OBJECT :
2120
- $ reply ->httpstatus = $ httpstatus ;
2121
- $ reply ->rate = $ rate ;
2122
- break ;
2123
- }
2109
+
2110
+ $ reply = $ this ->_appendHttpStatusAndRate ($ reply , $ httpstatus , $ rate );
2124
2111
return $ reply ;
2125
2112
}
2126
2113
@@ -2213,6 +2200,34 @@ protected function _callApiPreparationsPost(
2213
2200
return [$ authorization , $ params , $ request_headers ];
2214
2201
}
2215
2202
2203
+ /**
2204
+ * Appends HTTP status and rate limiting info to the reply
2205
+ *
2206
+ * @param array|object $reply The reply to append to
2207
+ * @param string $httpstatus The HTTP status code to append
2208
+ * @param mixed $rate The rate limiting info to append
2209
+ */
2210
+ protected function _appendHttpStatusAndRate ($ reply , $ httpstatus , $ rate )
2211
+ {
2212
+ switch ($ this ->_return_format ) {
2213
+ case CODEBIRD_RETURNFORMAT_ARRAY :
2214
+ $ reply ['httpstatus ' ] = $ httpstatus ;
2215
+ $ reply ['rate ' ] = $ rate ;
2216
+ break ;
2217
+ case CODEBIRD_RETURNFORMAT_OBJECT :
2218
+ $ reply ->httpstatus = $ httpstatus ;
2219
+ $ reply ->rate = $ rate ;
2220
+ break ;
2221
+ case CODEBIRD_RETURNFORMAT_JSON :
2222
+ $ reply = json_decode ($ reply );
2223
+ $ reply ->httpstatus = $ httpstatus ;
2224
+ $ reply ->rate = $ rate ;
2225
+ $ reply = json_encode ($ reply );
2226
+ break ;
2227
+ }
2228
+ return $ reply ;
2229
+ }
2230
+
2216
2231
/**
2217
2232
* Get Bearer authorization string
2218
2233
*
0 commit comments