8000 Extract _parseBearerReply method · SuperConnvrd/codebird-php@94984b3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 94984b3

Browse files
committed
Extract _parseBearerReply method
1 parent 331d08f commit 94984b3

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

src/codebird.php

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -665,31 +665,7 @@ protected function _oauth2TokenCurl()
665665
$this->_validateSslCertificate($validation_result);
666666

667667
$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);
693669
return $reply;
694670
}
695671

@@ -745,6 +721,25 @@ protected function _oauth2TokenNoCurl()
745721
$httpstatus = $match[1];
746722
}
747723

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+
{
748743
list($headers, $reply) = $this->_parseApiHeaders($result);
749744
$reply = $this->_parseApiReply($reply);
750745
$rate = $this->_getRateLimitInfo($headers);
@@ -773,11 +768,6 @@ protected function _oauth2TokenNoCurl()
773768
return $reply;
774769
}
775770

776-
777-
/**
778-
* General helpers to avoid duplicate code
779-
*/
780-
781771
/**
782772
* Extract rate-limiting data from response headers
783773
*

0 commit comments

Comments
 (0)
0