Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LCH-6977: Added webhook_version attribute in client metadata.
Browse files Browse the repository at this point in the history
narendradesai committed Jul 25, 2024
1 parent 6669aac commit 4908ac0
Showing 3 changed files with 19 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/MetaData/ClientMetaData.php
Original file line number Diff line number Diff line change
@@ -28,6 +28,13 @@ class ClientMetaData {
*/
protected bool $isSubscriber;

/**
* Wwebhook version.
*
* @var string
*/
protected string $webhookVersion;

/**
* Additional config metadata.
*
@@ -46,13 +53,16 @@ class ClientMetaData {
* Whether this site is a publiher or not.
* @param bool $is_subscriber
* Whether this site is a subscriber or not.
* @param string $webhook_version
* Version of webhook.
* @param array $client_config
* Additional config metadata.
*/
public function __construct(string $client_type, bool $is_publisher, bool $is_subscriber, array $client_config = []) {
public function __construct(string $client_type, bool $is_publisher, bool $is_subscriber, string $webhook_version, array $client_config = []) {
$this->clientType = $client_type;
$this->isPublisher = $is_publisher;
$this->isSubscriber = $is_subscriber;
$this->webhookVersion = $webhook_version;
$this->clientConfig = $client_config;
}

@@ -70,12 +80,13 @@ public static function fromArray(array $metadata): ClientMetadata {
$metadata['client_type'] = '';
$metadata['is_publisher'] = FALSE;
$metadata['is_subscriber'] = FALSE;
$metadata['webhook_version'] = '2.0';
$metadata['config'] = [];
}
if (isset($metadata['client_type'], $metadata['is_publisher'], $metadata['is_subscriber'])) {
return new static($metadata['client_type'], $metadata['is_publisher'], $metadata['is_subscriber'], $metadata['config'] ?? []);
if (isset($metadata['client_type'], $metadata['is_publisher'], $metadata['is_subscriber'], $metadata['webhook_version'])) {
return new static($metadata['client_type'], $metadata['is_publisher'], $metadata['is_subscriber'], $metadata['webhook_version'], $metadata['config'] ?? []);
}
throw new \RuntimeException('All the attributes: "client_type", "is_publisher", "is_subscriber" are required.');
throw new \RuntimeException('All the attributes: "client_type", "is_publisher", "is_subscriber", "webhook_version" are required.');
}

/**
@@ -89,6 +100,7 @@ public function toArray(): array {
'client_type' => $this->clientType,
'is_publisher' => $this->isPublisher,
'is_subscriber' => $this->isSubscriber,
'webhook_version' => $this->webhookVersion,
'config' => $this->clientConfig,
];
}
1 change: 1 addition & 0 deletions test/ContentHubClientTest.php
Original file line number Diff line number Diff line change
@@ -125,6 +125,7 @@ public function setUp(): void {
'client_type' => 'drupal',
'is_publisher' => TRUE,
'is_subscriber' => FALSE,
'webhook_version' => '2.0',
'config' => [
'valid_ssl' => TRUE,
'drupal_version' => '10.1.1',
3 changes: 2 additions & 1 deletion test/MetaData/ClientMetaDataTest.php
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ class ClientMetaDataTest extends TestCase {
'client_type' => 'drupal',
'is_publisher' => TRUE,
'is_subscriber' => FALSE,
'webhook_version' => '2.0',
'config' => [
'valid_ssl' => TRUE,
'drupal_version' => '10.1.1',
@@ -41,7 +42,7 @@ class ClientMetaDataTest extends TestCase {
* @covers ::toArray
*/
public function testGetMetaData(): void {
$this->sut = new ClientMetaData($this->metadata['client_type'], $this->metadata['is_publisher'], $this->metadata['is_subscriber'], $this->metadata['config']);
$this->sut = new ClientMetaData($this->metadata['client_type'], $this->metadata['is_publisher'], $this->metadata['is_subscriber'], $this->metadata['webhook_version'], $this->metadata['config']);
$client_metadata = $this->sut->toArray();
$this->assertEquals($this->metadata, $client_metadata);
}

0 comments on commit 4908ac0

Please sign in to comment.