From 3692914617d9b5c6f7c9d37f3b8328bef4be696c Mon Sep 17 00:00:00 2001 From: omitech Date: Fri, 31 Jan 2025 09:43:21 +0100 Subject: [PATCH 1/9] allow PUT method --- src/Client.php | 14 ++++++++++++++ src/Http/Method.php | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 9d1edc7..c50b73c 100644 --- a/src/Client.php +++ b/src/Client.php @@ -597,6 +597,20 @@ public function delete($endpoint, array $params = []) return $this->api($endpoint, $params, Method::DELETE); } + /** + * Make API call to LinkedIn using PUT method + * + * @param string $endpoint + * @param array $params + * + * @return array + * @throws \LinkedIn\Exception + */ + public function put($endpoint, array $params = []) + { + return $this->api($endpoint, $params, Method::PUT); + } + /** * @param $path * @return array diff --git a/src/Http/Method.php b/src/Http/Method.php index bd95661..73cc45d 100644 --- a/src/Http/Method.php +++ b/src/Http/Method.php @@ -72,7 +72,7 @@ class Method extends AbstractEnum */ public static function isMethodSupported($method) { - if (!in_array($method, [Method::GET, Method::POST, Method::DELETE])) { + if (!in_array($method, [Method::GET, Method::POST, Method::DELETE, Method::PUT])) { throw new \InvalidArgumentException('The method is not correct'); } } From 3c34cd785a194f8485f75f40d5e7636d0930ece0 Mon Sep 17 00:00:00 2001 From: omitech Date: Fri, 31 Jan 2025 10:13:14 +0100 Subject: [PATCH 2/9] Client::responseToArray check for Content-Length header --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index c50b73c..3ac4375 100644 --- a/src/Client.php +++ b/src/Client.php @@ -352,7 +352,7 @@ public function renewTokenFromRefreshToken($refreshToken = '') */ public static function responseToArray($response) { - if ($contents = $response->getBody()->getContents()) { + if ($response->getHeaderLine('Content-Length') > 0 && ($contents = $response->getBody()->getContents())) { return \GuzzleHttp\json_decode( $contents, true From 7c0a80455c1cfadbb19048e02ccf9ebe12efd3db Mon Sep 17 00:00:00 2001 From: omitech Date: Fri, 31 Jan 2025 10:16:00 +0100 Subject: [PATCH 3/9] revert Client::responseToArray --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 3ac4375..c50b73c 100644 --- a/src/Client.php +++ b/src/Client.php @@ -352,7 +352,7 @@ public function renewTokenFromRefreshToken($refreshToken = '') */ public static function responseToArray($response) { - if ($response->getHeaderLine('Content-Length') > 0 && ($contents = $response->getBody()->getContents())) { + if ($contents = $response->getBody()->getContents()) { return \GuzzleHttp\json_decode( $contents, true From 56abd55b49239441543634b704c43b092a42db85 Mon Sep 17 00:00:00 2001 From: omitech Date: Fri, 31 Jan 2025 10:17:15 +0100 Subject: [PATCH 4/9] Client::api empty body on PUT request --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index c50b73c..d5024c4 100644 --- a/src/Client.php +++ b/src/Client.php @@ -553,7 +553,7 @@ public function api($endpoint, array $params = [], $method = Method::GET) } catch (RequestException $requestException) { throw Exception::fromRequestException($requestException); } - return self::responseToArray($response); + return ($method != Method::PUT) ? self::responseToArray($response) : []; } /** From 578b58b5efa2b12f350309ee75125b9fb823c322 Mon Sep 17 00:00:00 2001 From: omitech Date: Fri, 31 Jan 2025 10:26:01 +0100 Subject: [PATCH 5/9] Client:put --- src/Client.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index d5024c4..8c4262d 100644 --- a/src/Client.php +++ b/src/Client.php @@ -553,7 +553,7 @@ public function api($endpoint, array $params = [], $method = Method::GET) } catch (RequestException $requestException) { throw Exception::fromRequestException($requestException); } - return ($method != Method::PUT) ? self::responseToArray($response) : []; + return self::responseToArray($response); } /** @@ -608,7 +608,26 @@ public function delete($endpoint, array $params = []) */ public function put($endpoint, array $params = []) { - return $this->api($endpoint, $params, Method::PUT); + if (false === is_resource($params['body'])) { + throw new \InvalidArgumentException( + sprintf('Argument must be a valid resource type. %s given.', gettype($resource)) + ); + } + + try { + (new GuzzleClient())->put( + $endpoint, + [ + 'headers' => [ + 'Authorization' => 'Bearer ' . $this->accessToken->getToken() + ], + 'body' => $resource + ] + ); + } catch (RequestException $requestException) { + throw Exception::fromRequestException($requestException); + } + } /** From faf2cd93be17e6770ce0703772ae669646ca0df4 Mon Sep 17 00:00:00 2001 From: omitech Date: Fri, 31 Jan 2025 10:27:39 +0100 Subject: [PATCH 6/9] Client::put fix $params --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 8c4262d..9b2d820 100644 --- a/src/Client.php +++ b/src/Client.php @@ -621,7 +621,7 @@ public function put($endpoint, array $params = []) 'headers' => [ 'Authorization' => 'Bearer ' . $this->accessToken->getToken() ], - 'body' => $resource + $params ] ); } catch (RequestException $requestException) { From f4dc86e0d437f8c5eae18f2cc786e9f576010655 Mon Sep 17 00:00:00 2001 From: omitech Date: Fri, 31 Jan 2025 10:32:30 +0100 Subject: [PATCH 7/9] Client::put merge $params --- src/Client.php | 12 ++++++++---- src/Http/Method.php | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Client.php b/src/Client.php index 9b2d820..ba34cf2 100644 --- a/src/Client.php +++ b/src/Client.php @@ -618,10 +618,14 @@ public function put($endpoint, array $params = []) (new GuzzleClient())->put( $endpoint, [ - 'headers' => [ - 'Authorization' => 'Bearer ' . $this->accessToken->getToken() - ], - $params + array_merge( + [ + 'headers' => [ + 'Authorization' => 'Bearer ' . $this->accessToken->getToken() + ] + ], + $params + ) ] ); } catch (RequestException $requestException) { diff --git a/src/Http/Method.php b/src/Http/Method.php index 73cc45d..bd95661 100644 --- a/src/Http/Method.php +++ b/src/Http/Method.php @@ -72,7 +72,7 @@ class Method extends AbstractEnum */ public static function isMethodSupported($method) { - if (!in_array($method, [Method::GET, Method::POST, Method::DELETE, Method::PUT])) { + if (!in_array($method, [Method::GET, Method::POST, Method::DELETE])) { throw new \InvalidArgumentException('The method is not correct'); } } From 56e8440ad6e340ba9c6163d2a590ee41f3728527 Mon Sep 17 00:00:00 2001 From: omitech Date: Fri, 31 Jan 2025 10:36:29 +0100 Subject: [PATCH 8/9] Client::put --- src/Client.php | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/Client.php b/src/Client.php index ba34cf2..315c335 100644 --- a/src/Client.php +++ b/src/Client.php @@ -601,14 +601,14 @@ public function delete($endpoint, array $params = []) * Make API call to LinkedIn using PUT method * * @param string $endpoint - * @param array $params + * @param resource $resource * * @return array * @throws \LinkedIn\Exception */ - public function put($endpoint, array $params = []) + public function put($endpoint, $resource) { - if (false === is_resource($params['body'])) { + if (false === is_resource($resource)) { throw new \InvalidArgumentException( sprintf('Argument must be a valid resource type. %s given.', gettype($resource)) ); @@ -618,20 +618,15 @@ public function put($endpoint, array $params = []) (new GuzzleClient())->put( $endpoint, [ - array_merge( - [ - 'headers' => [ - 'Authorization' => 'Bearer ' . $this->accessToken->getToken() - ] - ], - $params - ) + 'headers' => [ + 'Authorization' => 'Bearer ' . $this->accessToken->getToken() + ], + 'body' => $resource ] ); } catch (RequestException $requestException) { throw Exception::fromRequestException($requestException); } - } /** From 99d54576707ca45fc4ad5ece247dc8316b4a324d Mon Sep 17 00:00:00 2001 From: omitech Date: Wed, 28 May 2025 07:55:13 +0200 Subject: [PATCH 9/9] Return type of JsonSerializable php8.1 fix --- src/AccessToken.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AccessToken.php b/src/AccessToken.php index 9c4c37b..85fb47b 100644 --- a/src/AccessToken.php +++ b/src/AccessToken.php @@ -241,7 +241,7 @@ private static function validateRefreshTokenExpiresIn($responseArray) /** * Specify data format for json_encode() */ - public function jsonSerialize() + public function jsonSerialize(): mixed { return [ 'token' => $this->getToken(),