@@ -128,7 +128,7 @@ public function setUseTokenParam($useTokenParam)
128128 *
129129 * @var array
130130 */
131- protected $ defaultApiHeaders = [
131+ protected $ apiHeaders = [
132132 'Content-Type ' => 'application/json ' ,
133133 'x-li-format ' => 'json ' ,
134134 ];
@@ -138,21 +138,21 @@ public function setUseTokenParam($useTokenParam)
138138 *
139139 * @return array
140140 */
141- public function getDefaultApiHeaders ()
141+ public function getApiHeaders ()
142142 {
143- return $ this ->defaultApiHeaders ;
143+ return $ this ->apiHeaders ;
144144 }
145145
146146 /**
147147 * Set list of default headers
148148 *
149- * @param array $defaultApiHeaders
149+ * @param array $apiHeaders
150150 *
151151 * @return Client
152152 */
153- public function setDefaultApiHeaders ( $ defaultApiHeaders )
153+ public function setApiHeaders ( $ apiHeaders )
154154 {
155- $ this ->defaultApiHeaders = $ defaultApiHeaders ;
155+ $ this ->apiHeaders = $ apiHeaders ;
156156 return $ this ;
157157 }
158158
@@ -290,20 +290,11 @@ public function getAccessToken($code = '')
290290 ]);
291291 try {
292292 $ response = $ guzzle ->get ($ uri );
293- } catch (RequestException $ requestException ) {
294- $ json = self ::responseToArray (
295- $ requestException ->getResponse ()
296- );
297- throw new Exception (
298- $ requestException ->getMessage (),
299- $ requestException ->getCode (),
300- $ requestException ,
301- static ::extractErrorDescription ($ json )
302- );
293+ } catch (RequestException $ exception ) {
294+ throw Exception::fromRequestException ($ exception );
303295 }
304- $ json = self ::responseToArray ($ response );
305296 $ this ->setAccessToken (
306- AccessToken::fromResponseArray ( $ json )
297+ AccessToken::fromResponse ( $ response )
307298 );
308299 }
309300 return $ this ->accessToken ;
@@ -316,7 +307,7 @@ public function getAccessToken($code = '')
316307 *
317308 * @return array
318309 */
319- protected static function responseToArray ($ response )
310+ public static function responseToArray ($ response )
320311 {
321312 return \GuzzleHttp \json_decode (
322313 $ response ->getBody ()->getContents (),
@@ -491,7 +482,7 @@ protected function buildUrl($endpoint, $params)
491482 */
492483 public function api ($ endpoint , array $ params = [], $ method = Method::GET )
493484 {
494- $ headers = $ this ->getDefaultApiHeaders ();
485+ $ headers = $ this ->getApiHeaders ();
495486 $ uri = $ endpoint ;
496487 $ options = [];
497488 if ($ this ->isUsingTokenParam ()) {
@@ -524,34 +515,12 @@ public function api($endpoint, array $params = [], $method = Method::GET)
524515 try {
525516 $ response = $ guzzle ->request ($ method , $ uri , $ options );
526517 } catch (RequestException $ requestException ) {
527- $ json = self ::responseToArray (
528- $ requestException ->getResponse ()
529- );
530- throw new Exception (
531- $ requestException ->getMessage (),
532- $ requestException ->getCode (),
533- $ requestException ,
534- static ::extractErrorDescription ($ json )
535- );
518+ throw Exception::fromRequestException ($ requestException );
536519 }
537520 return self ::responseToArray ($ response );
538521 }
539522
540- /**
541- * @param $json
542- *
543- * @return null|string
544- */
545- private static function extractErrorDescription ($ json )
546- {
547- if (isset ($ json ['error_description ' ])) {
548- return $ json ['error_description ' ];
549- } elseif (isset ($ json ['message ' ])) {
550- return $ json ['message ' ];
551- } else {
552- return null ;
553- }
554- }
523+
555524
556525 /**
557526 * Make API call to LinkedIn using GET method
0 commit comments