From b19a831276478bd780582f22fd4ff9ce624bdb14 Mon Sep 17 00:00:00 2001 From: andrei-ghenov Date: Sat, 2 Mar 2024 22:36:36 -0500 Subject: [PATCH] T-005: Generate the timestamp in the specified format and ensure it's in GMT/UTC --- src/Api/ApiClient.php | 5 ++--- tests/Api/ApiClientTest.php | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Api/ApiClient.php b/src/Api/ApiClient.php index 3efef73..2d6560a 100644 --- a/src/Api/ApiClient.php +++ b/src/Api/ApiClient.php @@ -76,8 +76,8 @@ public function sendRequest( string $endpoint, array $data = [] ): mixed { - $dateTime = new DateTime('now', new DateTimeZone('America/New_York')); - $timestamp = $dateTime->format('c'); + // Generate the timestamp in the specified format and ensure it's in GMT/UTC + $timestamp = gmdate('Y-m-d\TH:i:s'); $authKey = $this->generateAuthHmac($timestamp, $this->apiSecurityKey); $hashedPassword = $this->generateAuthHmac($this->apiPassword, $authKey); @@ -88,7 +88,6 @@ public function sendRequest( 'User' => $this->apiUser, 'Password' => $hashedPassword, ], $data); - try { $response = $this->client->request($method, $endpoint, [ 'json' => $data, diff --git a/tests/Api/ApiClientTest.php b/tests/Api/ApiClientTest.php index 8496a72..6a1feab 100644 --- a/tests/Api/ApiClientTest.php +++ b/tests/Api/ApiClientTest.php @@ -30,11 +30,11 @@ public function testWSLoginSuccess() { // Use PHPUnit assertions to check for successful login // Display the response for debugging purposes - // (usually done during development only) + // (usually done during development only). echo "Response: "; var_dump($response); - // Assert the response indicates a successful login + // Assert the response indicates a successful login. $this->assertArrayHasKey( 'AccessCode', $response, "Response does not contain AccessCode" ); @@ -48,7 +48,7 @@ public function testWSLoginSuccess() { // In production or CI environments, it might be better to log this error // or handle it accordingly. echo "Error during WSLogin request: ".$e->getMessage(); - // Fail the test if an exception is caught + // Fail the test if an exception is caught. $this->fail( "WSLogin request failed with an exception: ".$e->getMessage() ); @@ -66,7 +66,7 @@ public function testWSLoginFailure() { 'Password' => 'incorrectPassword', ]); - // Debugging output (use sparingly) + // Debugging output (use sparingly). echo "Response: "; var_dump($response);