-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathWebhooksApi.php
64 lines (52 loc) · 1.77 KB
/
WebhooksApi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace BigCommerce\ApiV3\Api\Webhooks;
use BigCommerce\ApiV3\Api\Generic\ResourceApi;
use BigCommerce\ApiV3\ResourceModels\Webhook\Webhook;
use BigCommerce\ApiV3\ResponseModels\Webhook\WebhookResponse;
use BigCommerce\ApiV3\ResponseModels\Webhook\WebhooksResponse;
class WebhooksApi extends ResourceApi
{
public const WEBHOOK_ENDPOINT = 'hooks/%d';
public const WEBHOOKS_ENDPOINT = 'hooks';
public const RESOURCE_NAME = 'hooks';
public function get(): WebhookResponse
{
return new WebhookResponse($this->getResource());
}
/**
* Creates a webhook. Only one webhook at a time can be created. Custom headers can be added.
* Destination URL must be served on port 443 (custom ports are not currently supported).
*/
public function create(Webhook $webhook): WebhookResponse
{
return new WebhookResponse($this->createResource($webhook));
}
public function update(Webhook $webhook): WebhookResponse
{
return new WebhookResponse($this->updateResource($webhook));
}
protected function singleResourceEndpoint(): string
{
return self::WEBHOOK_ENDPOINT;
}
protected function multipleResourcesEndpoint(): string
{
return self::WEBHOOKS_ENDPOINT;
}
protected function resourceName(): string
{
return self::RESOURCE_NAME;
}
public function getAll(array $filters = [], int $page = 1, int $limit = 250): WebhooksResponse
{
return new WebhooksResponse($this->getAllResources($filters, $page, $limit));
}
public function events(): WebhookEventsApi
{
return new WebhookEventsApi($this->getClient());
}
public function admin(): WebhookAdminApi
{
return new WebhookAdminApi($this->getClient());
}
}