Skip to content

Commit

Permalink
Adding new fields to subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
rojtjo committed Dec 20, 2023
1 parent 119c4cc commit b217ccc
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 14 deletions.
16 changes: 10 additions & 6 deletions src/Connectors/SubscriptionConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Rojtjo\Bol\Types\SignatureKeyCollection;
use Rojtjo\Bol\Types\Subscription;
use Rojtjo\Bol\Types\SubscriptionCollection;
use Rojtjo\Bol\Types\SubscriptionType;

final class SubscriptionConnector extends ConnectorAbstract
{
Expand Down Expand Up @@ -39,21 +40,24 @@ public function findSubscription(string $subscriptionId): Subscription
return Subscription::fromPayload($data);
}

public function createSubscription(array $resources, string $url): ProcessStatus
public function createSubscription(array $resources, string $url, SubscriptionType $subscriptionType): ProcessStatus
{
$data = $this->send('POST', 'subscriptions', body: [
'resources' => $resources,
'url' => $url,
'resources' => $resources,
'url' => $url,
'subscriptionType' => $subscriptionType->value,
]);

return ProcessStatus::fromPayload($data);
}

public function updateSubscription(string $subscriptionId, array $resources, string $url): ProcessStatus
public function updateSubscription(string $subscriptionId, array $resources, string $url, SubscriptionType $subscriptionType, bool $enabled): ProcessStatus
{
$data = $this->send('PUT', "subscriptions/$subscriptionId", body: [
'resources' => $resources,
'url' => $url,
'resources' => $resources,
'url' => $url,
'subscriptionType' => $subscriptionType->value,
'enabled' => $enabled
]);

return ProcessStatus::fromPayload($data);
Expand Down
4 changes: 4 additions & 0 deletions src/Types/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public function __construct(
public readonly string $id,
public readonly array $resources,
public readonly string $url,
public readonly SubscriptionType $subscriptionType,
public readonly bool $enabled,
)
{
}
Expand All @@ -20,6 +22,8 @@ public static function fromPayload(array $subscription): self
$subscription['id'],
$subscription['resources'],
$subscription['url'],
SubscriptionType::from($subscription['subscriptionType']),
$subscription['enabled'],
);
}
}
12 changes: 12 additions & 0 deletions src/Types/SubscriptionType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Rojtjo\Bol\Types;

enum SubscriptionType: string
{
case Webhook = 'WEBHOOK';

case GCPPubSub = 'GCP_PUBSUB';
}
28 changes: 20 additions & 8 deletions tests/Integration/SubscriptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

namespace Tests\Integration;

use Rojtjo\Bol\Types\SubscriptionType;

final class SubscriptionsTest extends IntegrationTestCase
{
/**
* @test
* @see https://api.bol.com/retailer/public/api/demo/v10-SUBSCRIPTIONS.html#_retrieve_push_notification_subscription_list
* @see https://api.bol.com/retailer/public/Retailer-API/demo/v10-SUBSCRIPTIONS.html#_retrieve_push_notification_subscription_list
*/
public function retrieve_push_notification_subscription_list(): void
{
Expand All @@ -21,7 +23,7 @@ public function retrieve_push_notification_subscription_list(): void

/**
* @test
* @see https://api.bol.com/retailer/public/api/demo/v10-SUBSCRIPTIONS.html#_trigger_sending_of_a_test_push_notification_for_subscription
* @see https://api.bol.com/retailer/public/Retailer-API/demo/v10-SUBSCRIPTIONS.html#_trigger_sending_of_a_test_push_notification_for_subscription
*/
public function trigger_sending_of_a_test_push_notification_for_subscription(): void
{
Expand All @@ -34,20 +36,24 @@ public function trigger_sending_of_a_test_push_notification_for_subscription():

/**
* @test
* @see https://api.bol.com/retailer/public/api/demo/v10-SUBSCRIPTIONS.html#_create_push_notification_subscription
* @see https://api.bol.com/retailer/public/Retailer-API/demo/v10-SUBSCRIPTIONS.html#_create_push_notification_subscription
*/
public function create_push_notification_subscription(): void
{
$processStatus = $this->bol
->subscriptions()
->createSubscription(['PROCESS_STATUS'], 'https://www.example.com/push');
->createSubscription(
['PROCESS_STATUS'],
'https://www.example.com/push',
SubscriptionType::Webhook,
);

$this->assertMatchesObjectSnapshot($processStatus->withFixedTimestamp());
}

/**
* @test
* @see https://api.bol.com/retailer/public/api/demo/v10-SUBSCRIPTIONS.html#_delete_existing_push_notification_subscription
* @see https://api.bol.com/retailer/public/Retailer-API/demo/v10-SUBSCRIPTIONS.html#_delete_existing_push_notification_subscription
*/
public function delete_existing_push_notification_subscription(): void
{
Expand All @@ -60,7 +66,7 @@ public function delete_existing_push_notification_subscription(): void

/**
* @test
* @see https://api.bol.com/retailer/public/api/demo/v10-SUBSCRIPTIONS.html#_retrieve_push_notification_subscription
* @see https://api.bol.com/retailer/public/Retailer-API/demo/v10-SUBSCRIPTIONS.html#_retrieve_push_notification_subscription
*/
public function retrieve_push_notification_subscription(): void
{
Expand All @@ -73,13 +79,19 @@ public function retrieve_push_notification_subscription(): void

/**
* @test
* @see https://api.bol.com/retailer/public/api/demo/v10-SUBSCRIPTIONS.html#_update_existing_push_notification_subscription
* @see https://api.bol.com/retailer/public/Retailer-API/demo/v10-SUBSCRIPTIONS.html#_update_existing_push_notification_subscription
*/
public function update_existing_push_notification_subscription(): void
{
$processStatus = $this->bol
->subscriptions()
->updateSubscription('1234', ['PROCESS_STATUS'], 'https://www.example.com/push');
->updateSubscription(
'1234',
['PROCESS_STATUS'],
'https://www.example.com/push',
SubscriptionType::Webhook,
false,
);

$this->assertMatchesObjectSnapshot($processStatus->withFixedTimestamp());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ id: '1234'
resources:
- PROCESS_STATUS
url: 'https://www.example.com/push'
subscriptionType:
name: Webhook
value: WEBHOOK
enabled: true
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
id: '1234'
resources: [PROCESS_STATUS]
url: 'https://www.example.com/push'
subscriptionType: { name: Webhook, value: WEBHOOK }
enabled: true

0 comments on commit b217ccc

Please sign in to comment.