@@ -665,31 +665,7 @@ protected function _oauth2TokenCurl()
665
665
$ this ->_validateSslCertificate ($ validation_result );
666
666
667
667
$ httpstatus = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
668
- list ($ headers , $ reply ) = $ this ->_parseApiHeaders ($ result );
669
- $ reply = $ this ->_parseApiReply ($ reply );
670
- $ rate = $ this ->_getRateLimitInfo ($ headers );
671
- switch ($ this ->_return_format ) {
672
- case CODEBIRD_RETURNFORMAT_ARRAY :
673
- $ reply ['httpstatus ' ] = $ httpstatus ;
674
- $ reply ['rate ' ] = $ rate ;
675
- if ($ httpstatus === 200 ) {
676
- self ::setBearerToken ($ reply ['access_token ' ]);
677
- }
6
10000
78
- break ;
679
- case CODEBIRD_RETURNFORMAT_JSON :
680
- if ($ httpstatus === 200 ) {
681
- $ parsed = json_decode ($ reply );
682
- self ::setBearerToken ($ parsed ->access_token );
683
- }
684
- break ;
685
- case CODEBIRD_RETURNFORMAT_OBJECT :
686
- $ reply ->httpstatus = $ httpstatus ;
687
- $ reply ->rate = $ rate ;
688
- if ($ httpstatus === 200 ) {
689
- self ::setBearerToken ($ reply ->access_token );
690
- }
691
- break ;
692
- }
668
+ $ reply = $ this ->_parseBearerReply ($ result , $ httpstatus );
693
669
return $ reply ;
694
670
}
695
671
@@ -745,6 +721,25 @@ protected function _oauth2TokenNoCurl()
745
721
$ httpstatus = $ match [1 ];
746
722
}
747
723
724
+ $ reply = $ this ->_parseBearerReply ($ result , $ httpstatus );
725
+ return $ reply ;
726
+ }
727
+
728
+
729
+ /**
730
+ * General helpers to avoid duplicate code
731
+ */
732
+
733
+ /**
734
+ * Parse oauth2_token reply and set bearer token, if found
735
+ *
736
+ * @param string $result Raw HTTP response
737
+ * @param int $httpstatus HTTP status code
738
+ *
739
+ * @return array|object reply
740
+ */
741
+ protected function _parseBearerReply ($ result , $ httpstatus )
742
+ {
748
743
list ($ headers , $ reply ) = $ this ->_parseApiHeaders ($ result );
749
744
$ reply = $ this ->_parseApiReply ($ reply );
750
745
$ rate = $ this ->_getRateLimitInfo ($ headers );
@@ -773,11 +768,6 @@ protected function _oauth2TokenNoCurl()
773
768
return $ reply ;
774
769
}
775
770
776
-
777
- /**
778
- * General helpers to avoid duplicate code
779
- */
780
-
781
771
/**
782
772
* Extract rate-limiting data from response headers
783
773
*
0 commit comments