|
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 ContactApi implements ContactApiResourceInterface |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var CommonResourceClientInterface |
|
22
|
|
|
*/ |
|
23
|
|
|
private $resourceClient; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var PageFactoryInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
private $pageFactory; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var ResourceCursorFactoryInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
private $cursorFactory; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param CommonResourceClientInterface $resourceClient |
|
37
|
|
|
* @param PageFactoryInterface $pageFactory |
|
38
|
|
|
* @param ResourceCursorFactoryInterface $cursorFactory |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct( |
|
41
|
|
|
CommonResourceClientInterface $resourceClient, |
|
42
|
|
|
PageFactoryInterface $pageFactory, |
|
43
|
|
|
ResourceCursorFactoryInterface $cursorFactory |
|
44
|
|
|
) { |
|
45
|
|
|
$this->resourceClient = $resourceClient; |
|
46
|
|
|
$this->pageFactory = $pageFactory; |
|
47
|
|
|
$this->cursorFactory = $cursorFactory; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @inheritDoc |
|
52
|
|
|
*/ |
|
53
|
|
|
public function get(int $id): array |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->resourceClient->getResource('api/3/contacts/%s', [$id]); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @inheritDoc |
|
60
|
|
|
*/ |
|
61
|
|
|
public function listPerPage(int $limit = 100, int $offset = 0, array $queryParameters = []): PageInterface |
|
62
|
|
|
{ |
|
63
|
|
|
$response = $this->resourceClient->getResources( |
|
64
|
|
|
'api/3/contacts', |
|
65
|
|
|
[], |
|
66
|
|
|
$limit, |
|
67
|
|
|
$offset, |
|
68
|
|
|
$queryParameters |
|
69
|
|
|
); |
|
70
|
|
|
|
|
71
|
|
|
return $this->pageFactory->createPage($this, $response['contacts'], $response['meta']); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @inheritDoc |
|
76
|
|
|
*/ |
|
77
|
|
|
public function all(int $limit = 100, array $queryParameters = []): ResourceCursorInterface |
|
78
|
|
|
{ |
|
79
|
|
|
$firstPage = $this->listPerPage($limit, 0, $queryParameters); |
|
80
|
|
|
return $this->cursorFactory->createCursor($limit, $firstPage); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @inheritDoc |
|
85
|
|
|
*/ |
|
86
|
|
|
public function create(array $data): array |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->resourceClient->createResource('api/3/contacts', [], $data); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @inheritDoc |
|
93
|
|
|
*/ |
|
94
|
|
|
public function update(int $id, array $data = []): array |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->resourceClient->updateResource('api/3/contacts/%s', [$id], $data); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @inheritDoc |
|
101
|
|
|
*/ |
|
102
|
|
|
public function upsert(array $data = []): array |
|
103
|
|
|
{ |
|
104
|
|
|
return $this->resourceClient->upsertResource('api/3/contact/sync', [], $data); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @inheritDoc |
|
109
|
|
|
*/ |
|
110
|
|
|
public function delete(int $id): bool |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->resourceClient->deleteResource('api/3/contacts/%s', [$id]); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Update list status for a contact |
|
117
|
|
|
* |
|
118
|
|
|
* @param array $data |
|
119
|
|
|
* |
|
120
|
|
|
* @return array |
|
121
|
|
|
*/ |
|
122
|
|
|
public function updateListStatus(array $data): array |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->resourceClient->createResource('api/3/contactList', [], $data); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|