From f5945961e33a373b0898c9c1c72fc18ffd4c191f Mon Sep 17 00:00:00 2001 From: Jesse Evers Date: Fri, 21 Jun 2024 01:35:23 -0400 Subject: [PATCH] Make user agent configurable --- src/SellingPartnerApi.php | 16 +++++++++++++++- src/Traits/Deserializes.php | 4 +++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/SellingPartnerApi.php b/src/SellingPartnerApi.php index 60a76f48f..b03d13afe 100644 --- a/src/SellingPartnerApi.php +++ b/src/SellingPartnerApi.php @@ -44,6 +44,8 @@ abstract class SellingPartnerApi extends Connector protected TokensV20210301\Api $tokensApi; + protected string $userAgent; + public function __construct( public readonly string $clientId, public readonly string $clientSecret, @@ -188,9 +190,21 @@ function () use ($method, $path, $dataElements, $delegatee, $tokensApi): AccessT public function getUserAgent(): string { + if (isset($this->userAgent)) { + return $this->userAgent; + } + $version = Package::version(); + $this->userAgent = "jlevers/selling-partner-api/v$version/php"; + + return $this->userAgent; + } + + public function setUserAgent(string $userAgent): static + { + $this->userAgent = $userAgent; - return "jlevers/selling-partner-api/v$version/php"; + return $this; } /** diff --git a/src/Traits/Deserializes.php b/src/Traits/Deserializes.php index e66f20593..4312e7e26 100644 --- a/src/Traits/Deserializes.php +++ b/src/Traits/Deserializes.php @@ -15,11 +15,13 @@ trait Deserializes use HasComplexArrayTypes; protected static string $datetimeFormat = 'Y-m-d\TH:i:s\Z'; + protected static string $dateFormat = 'Y-m-d'; + protected static array $validDatetimeFormats = [ 'Y-m-d\TH:i:s\Z', DATE_ATOM, - 'Y-m-d' + 'Y-m-d', ]; public static function deserialize(mixed $data): mixed