From 00ed99a0eb067a5913c80f358baa3841594e596f Mon Sep 17 00:00:00 2001 From: Leonard Breitkopf Date: Tue, 9 Feb 2021 09:46:35 +0100 Subject: [PATCH 1/2] #25: Strip null properties from request body --- lib/RequestHandler.php | 5 +++-- lib/Util/NullStripper.php | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 lib/Util/NullStripper.php diff --git a/lib/RequestHandler.php b/lib/RequestHandler.php index 43bf69e..9ccd46d 100644 --- a/lib/RequestHandler.php +++ b/lib/RequestHandler.php @@ -5,6 +5,7 @@ use Trunkrs\SDK\Exception\GeneralApiException; use Trunkrs\SDK\Exception\NotAuthorizedException; use Trunkrs\SDK\Exception\ServerValidationException; +use Trunkrs\SDK\Util\NullStripper; class RequestHandler { private static $_httpClient; @@ -103,7 +104,7 @@ public static function post(string $resource, array $body) { "POST", self::createUrl($resource), self::createHeaders(!empty($body)), - $body + NullStripper::strip($body) ); if (!self::isSuccessful($response)) { @@ -127,7 +128,7 @@ public static function put(string $resource, array $body = []) { "PUT", self::createUrl($resource), self::createHeaders(!empty($body)), - $body + NullStripper::strip($body) ); if (!self::isSuccessful($response)) { diff --git a/lib/Util/NullStripper.php b/lib/Util/NullStripper.php new file mode 100644 index 0000000..e0dabe6 --- /dev/null +++ b/lib/Util/NullStripper.php @@ -0,0 +1,20 @@ + $value) { + if (is_array($value)) { + $array[$key] = NullStripper::strip($value); + } else if (is_null($value)) { + unset($key); + } + } + + return $array; + } +} \ No newline at end of file From c765507dae2aa7aa38b404a80731f2aa76e0394e Mon Sep 17 00:00:00 2001 From: Leonard Breitkopf Date: Tue, 9 Feb 2021 09:50:10 +0100 Subject: [PATCH 2/2] Bump: v2.0.2 --- VERSION | 2 +- lib/Settings.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 38f77a6..e9307ca 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.1 +2.0.2 diff --git a/lib/Settings.php b/lib/Settings.php index f46fed8..6a3a206 100644 --- a/lib/Settings.php +++ b/lib/Settings.php @@ -38,7 +38,7 @@ class Settings { /** * @var string The current version of the SDK. */ - public static $sdkVersion = '2.0.1'; + public static $sdkVersion = '2.0.2'; /** * Sets the client credentials that will be used in subsequent requests.