-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathPagesApi.php
More file actions
93 lines (75 loc) · 2.46 KB
/
Copy pathPagesApi.php
File metadata and controls
93 lines (75 loc) · 2.46 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
namespace BigCommerce\ApiV3\Api\Pages;
use BigCommerce\ApiV3\Api\Generic\BatchCreateResource;
use BigCommerce\ApiV3\Api\Generic\ResourceWithBatchUpdateApi;
use BigCommerce\ApiV3\ResourceModels\Page\Page;
use BigCommerce\ApiV3\ResponseModels\Page\PageResponse;
use BigCommerce\ApiV3\ResponseModels\Page\PagesResponse;
use GuzzleHttp\RequestOptions;
/**
* Includes the multiple and single page requests for pages
*/
class PagesApi extends ResourceWithBatchUpdateApi
{
use BatchCreateResource;
protected function maxBatchSize(): int
{
return 100;
}
private const PAGE_ENDPOINT = 'content/pages/%d';
private const PAGES_ENDPOINT = 'content/pages';
private const RESOURCE_NAME = 'pages';
public const FILTER_INCLUDE = 'include';
public function batchUpdate(array $resources): PagesResponse
{
return PagesResponse::buildFromMultipleResponses($this->batchCreateResource($resources));
}
protected function multipleResourcesEndpoint(): string
{
return self::PAGES_ENDPOINT;
}
protected function singleResourceEndpoint(): string
{
return self::PAGE_ENDPOINT;
}
protected function resourceName(): string
{
return self::RESOURCE_NAME;
}
public function get(?string $include = null): PageResponse
{
$params = [];
if (!is_null($include)) {
$params[self::FILTER_INCLUDE] = $include;
}
return new PageResponse($this->getResource($params));
}
public function getAll(array $filters = [], int $page = 1, int $limit = 250): PagesResponse
{
return new PagesResponse($this->getAllResources($filters, $page, $limit));
}
public function batchCreate(array $resources): PagesResponse
{
return PagesResponse::buildFromMultipleResponses($this->batchCreateResource($resources));
}
public function create(Page $page): PageResponse
{
return new PageResponse($this->createResource($page));
}
public function update(Page $page): PageResponse
{
return new PageResponse($this->updateResource($page));
}
public function batchDelete(array $ids = []): bool
{
$response = $this->getClient()->getRestClient()->delete(
$this->multipleResourceUrl(),
[
RequestOptions::QUERY => [
'id:in' => implode(',', $ids)
]
]
);
return $response->getStatusCode() === 204;
}
}