Skip to content

Commit a0ed5de

Browse files
committed
Optimize api() method
1 parent 07b659c commit a0ed5de

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

src/Client.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,6 @@ protected function buildUrl($endpoint, $params)
482482
public function api($endpoint, array $params = [], $method = Method::GET)
483483
{
484484
$headers = $this->getApiHeaders();
485-
$uri = $endpoint;
486485
$options = [];
487486
if ($this->isUsingTokenParam()) {
488487
$params['oauth2_access_token'] = $this->accessToken->getToken();
@@ -496,31 +495,23 @@ public function api($endpoint, array $params = [], $method = Method::GET)
496495
switch ($method) {
497496
case Method::GET:
498497
if (!empty($params)) {
499-
$uri .= '?' . build_query($params);
498+
$endpoint .= '?' . build_query($params);
500499
}
501500
break;
502501
case Method::POST:
503502
$options['body'] = \GuzzleHttp\json_encode($params);
504503
break;
505504
default:
506-
throw new Exception(
507-
"Method not defined",
508-
1,
509-
null,
510-
"Please, pass correct method!"
511-
);
505+
throw new \InvalidArgumentException('The method is not correct');
512506
}
513-
514507
try {
515-
$response = $guzzle->request($method, $uri, $options);
508+
$response = $guzzle->request($method, $endpoint, $options);
516509
} catch (RequestException $requestException) {
517510
throw Exception::fromRequestException($requestException);
518511
}
519512
return self::responseToArray($response);
520513
}
521514

522-
523-
524515
/**
525516
* Make API call to LinkedIn using GET method
526517
*

0 commit comments

Comments
 (0)