Skip to content

Commit

Permalink
Merge pull request #27 from aligent/feature/add-subscribers-api
Browse files Browse the repository at this point in the history
Feature/add subscribers api
  • Loading branch information
jswift authored Nov 20, 2020
2 parents f3fad6f + 8d58c00 commit 500785b
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Running tests: `composer run-script test`

#### Subscribers

- Subscribers
- ☑️ Subscribers

#### Themes

Expand Down
4 changes: 2 additions & 2 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
### Breaking Change
### New Features

API classes have been refactored to all be under the `Api/` namespace, with the exception of `Client`, which has not moved.
- Implement Subscribers API
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 500785b

Please sign in to comment.