22
33namespace Github \HttpClient \Message ;
44
5- use Guzzle \Http \Message \Response ;
65use Github \Exception \ApiLimitExceedException ;
6+ use Psr \Http \Message \ResponseInterface ;
77
88class ResponseMediator
99{
10- public static function getContent (Response $ response )
10+ public static function getContent (ResponseInterface $ response )
1111 {
12- $ body = $ response ->getBody (true );
13- if (strpos ($ response ->getContentType ( ), 'application/json ' ) === 0 ) {
12+ $ body = $ response ->getBody ()-> __toString ( );
13+ if (strpos ($ response ->getHeaderLine ( ' Content-Type ' ), 'application/json ' ) === 0 ) {
1414 $ content = json_decode ($ body , true );
1515 if (JSON_ERROR_NONE === json_last_error ()) {
1616 return $ content ;
@@ -20,14 +20,14 @@ public static function getContent(Response $response)
2020 return $ body ;
2121 }
2222
23- public static function getPagination (Response $ response )
23+ public static function getPagination (ResponseInterface $ response )
2424 {
25- $ header = (string ) $ response ->getHeader ('Link ' );
26-
27- if (empty ($ header )) {
25+ if ($ response ->hasHeader ('Link ' )) {
2826 return null ;
2927 }
3028
29+ $ header = $ response ->getHeader ('Link ' );
30+ $ header = array_shift ($ header );
3131 $ pagination = array ();
3232 foreach (explode (', ' , $ header ) as $ link ) {
3333 preg_match ('/<(.*)>; rel="(.*)"/i ' , trim ($ link , ', ' ), $ match );
@@ -40,9 +40,10 @@ public static function getPagination(Response $response)
4040 return $ pagination ;
4141 }
4242
43- public static function getApiLimit (Response $ response )
43+ public static function getApiLimit (ResponseInterface $ response )
4444 {
45- $ remainingCalls = (string ) $ response ->getHeader ('X-RateLimit-Remaining ' );
45+ $ remainingCalls = $ response ->getHeader ('X-RateLimit-Remaining ' );
46+ $ remainingCalls = array_shift ($ remainingCalls );
4647
4748 if (null !== $ remainingCalls && 1 > $ remainingCalls ) {
4849 throw new ApiLimitExceedException ($ remainingCalls );
0 commit comments