1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace CommerceLeague\ActiveCampaignApi\Api; |
7
|
|
|
|
8
|
|
|
use CommerceLeague\ActiveCampaignApi\Client\CommonResourceClientInterface; |
9
|
|
|
use CommerceLeague\ActiveCampaignApi\Paginator\PageFactoryInterface; |
10
|
|
|
use CommerceLeague\ActiveCampaignApi\Paginator\PageInterface; |
11
|
|
|
use CommerceLeague\ActiveCampaignApi\Paginator\ResourceCursorFactoryInterface; |
12
|
|
|
use CommerceLeague\ActiveCampaignApi\Paginator\ResourceCursorInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class ContactApi |
16
|
|
|
*/ |
17
|
|
|
class ListsApi implements ListsApiResourceInterface |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
const URL = 'api/3/lists'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var CommonResourceClientInterface |
24
|
|
|
*/ |
25
|
|
|
private $resourceClient; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var PageFactoryInterface |
29
|
|
|
*/ |
30
|
|
|
private $pageFactory; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var ResourceCursorFactoryInterface |
34
|
|
|
*/ |
35
|
|
|
private $cursorFactory; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param CommonResourceClientInterface $resourceClient |
39
|
|
|
* @param PageFactoryInterface $pageFactory |
40
|
|
|
* @param ResourceCursorFactoryInterface $cursorFactory |
41
|
|
|
*/ |
42
|
|
|
public function __construct( |
43
|
|
|
CommonResourceClientInterface $resourceClient, |
44
|
|
|
PageFactoryInterface $pageFactory, |
45
|
|
|
ResourceCursorFactoryInterface $cursorFactory |
46
|
|
|
) { |
47
|
|
|
$this->resourceClient = $resourceClient; |
48
|
|
|
$this->pageFactory = $pageFactory; |
49
|
|
|
$this->cursorFactory = $cursorFactory; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @inheritDoc |
54
|
|
|
*/ |
55
|
|
|
public function get(int $id): array |
56
|
|
|
{ |
57
|
|
|
return $this->resourceClient->getResource(self::URL . '/%s', [$id]); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @inheritDoc |
62
|
|
|
*/ |
63
|
|
|
public function listPerPage(int $limit = 100, int $offset = 0, array $queryParameters = []): PageInterface |
64
|
|
|
{ |
65
|
|
|
$response = $this->resourceClient->getResources( |
66
|
|
|
self::URL, |
67
|
|
|
[], |
68
|
|
|
$limit, |
69
|
|
|
$offset, |
70
|
|
|
$queryParameters |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
return $this->pageFactory->createPage($this, $response['lists'], $response['meta']); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @inheritDoc |
78
|
|
|
*/ |
79
|
|
|
public function all(int $limit = 100, array $queryParameters = []): ResourceCursorInterface |
80
|
|
|
{ |
81
|
|
|
$firstPage = $this->listPerPage($limit, 0, $queryParameters); |
82
|
|
|
return $this->cursorFactory->createCursor($limit, $firstPage); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @inheritDoc |
87
|
|
|
*/ |
88
|
|
|
public function create(array $data): array |
89
|
|
|
{ |
90
|
|
|
return $this->resourceClient->createResource(self::URL, [], $data); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @inheritDoc |
95
|
|
|
*/ |
96
|
|
|
public function delete(int $id): bool |
97
|
|
|
{ |
98
|
|
|
return $this->resourceClient->deleteResource(self::URL . '/%s', [$id]); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|