Skip to content

Commit

Permalink
Add scaffolding for Subscribers api
Browse files Browse the repository at this point in the history
  • Loading branch information
jswift committed Nov 20, 2020
1 parent f3fad6f commit c769488
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/BigCommerce/Api/Subscribers/SubscribersApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace BigCommerce\ApiV3\Api\Subscribers;

use BigCommerce\ApiV3\Api\Generic\ResourceApi;
use BigCommerce\ApiV3\ResponseModels\Customer\SubscriberResponse;
use BigCommerce\ApiV3\ResponseModels\Customer\SubscribersResponse;

class SubscribersApi extends ResourceApi
{
private const RESOURCE_NAME = 'subscribers';
private const SUBSCRIBER_ENDPOINT = 'customers/subscribers';
private const SUBSCRIBERS_ENDPOINT = 'customers/subscribers/%d';

protected function singleResourceEndpoint(): string
{
return self::SUBSCRIBER_ENDPOINT;
}

protected function multipleResourcesEndpoint(): string
{
return self::SUBSCRIBERS_ENDPOINT;
}

protected function resourceName(): string
{
return self::RESOURCE_NAME;
}

public function get(): SubscriberResponse
{
return new SubscriberResponse($this->getResource());
}

public function getAll(array $filters = [], int $page = 1, int $limit = 250): SubscribersResponse
{
return new SubscribersResponse($this->getAllResources($filters, $page, $limit));
}
}
22 changes: 22 additions & 0 deletions src/BigCommerce/ResourceModels/Customer/Subscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace BigCommerce\ApiV3\ResourceModels\Customer;

use BigCommerce\ApiV3\ResourceModels\ResourceModel;

class Subscriber extends ResourceModel
{
public const SOURCE_STOREFRONT = 'storefront';
public const SOURCE_ORDER = 'order';
public const SOURCE_CUSTOM = 'custom';

public string $email;
public string $first_name;
public string $last_name;
public string $source;
public int $order_id;
public int $channel_id;
public int $id;
public string $date_modified;
public string $date_created;
}
22 changes: 22 additions & 0 deletions src/BigCommerce/ResponseModels/Customer/SubscriberResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace BigCommerce\ApiV3\ResponseModels\Customer;

use BigCommerce\ApiV3\ResourceModels\Customer\Subscriber;
use BigCommerce\ApiV3\ResponseModels\SingleResourceResponse;
use stdClass;

class SubscriberResponse extends SingleResourceResponse
{
private Subscriber $subscriber;

public function getSubscriber(): Subscriber
{
return $this->subscriber;
}

protected function addData(stdClass $rawData): void
{
$this->subscriber = new Subscriber($rawData);
}
}
21 changes: 21 additions & 0 deletions src/BigCommerce/ResponseModels/Customer/SubscribersResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace BigCommerce\ApiV3\ResponseModels\Customer;

use BigCommerce\ApiV3\ResourceModels\Customer\Subscriber;
use BigCommerce\ApiV3\ResponseModels\PaginatedResponse;

class SubscribersResponse extends PaginatedResponse
{
/**
* @return Subscriber[]
*/
public function getSubscribers(): array
{
return $this->getData();
}
protected function resourceClass(): string
{
return Subscriber::class;
}
}
18 changes: 18 additions & 0 deletions tests/BigCommerce/Api/Subscribers/SubscribersApiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace BigCommerce\Tests\Api\Subscribers;

use BigCommerce\Tests\BigCommerceApiTest;

class SubscribersApiTest extends BigCommerceApiTest
{
public function testCanGetSubscriber(): void
{
$this->markTestIncomplete();
}

public function testCanGetSubscribers(): void
{
$this->markTestIncomplete();
}
}

0 comments on commit c769488

Please sign in to comment.