-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from aligent/feature/add-subscribers-api
Feature/add subscribers api
- Loading branch information
Showing
7 changed files
with
125 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
22
src/BigCommerce/ResponseModels/Customer/SubscriberResponse.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
src/BigCommerce/ResponseModels/Customer/SubscribersResponse.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |