1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://github.com/flipbox/hubspot/blob/master/LICENSE.md |
6
|
|
|
* @link https://github.com/flipbox/hubspot |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Flipbox\HubSpot\Criteria; |
10
|
|
|
|
11
|
|
|
use Flipbox\HubSpot\Resources\ContactListContacts; |
12
|
|
|
use Psr\Http\Message\ResponseInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author Flipbox Factory <[email protected]> |
16
|
|
|
* @since 2.0.0 |
17
|
|
|
*/ |
18
|
|
|
class ContactListContactsCriteria extends AbstractCriteria |
19
|
|
|
{ |
20
|
|
|
use ConnectionTrait, |
21
|
|
|
CacheTrait, |
22
|
|
|
IdAttributeTrait; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var array|null |
26
|
|
|
*/ |
27
|
|
|
protected $vids; |
28
|
|
|
/** |
29
|
|
|
* @var array|null |
30
|
|
|
*/ |
31
|
|
|
protected $emails; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return array |
35
|
|
|
* @throws \Exception |
36
|
|
|
*/ |
37
|
|
|
public function getVids(): array |
38
|
|
|
{ |
39
|
|
|
if (null === ($ids = $this->findVids())) { |
40
|
|
|
throw new \Exception("Invalid Contact Ids"); |
41
|
|
|
} |
42
|
|
|
return (array)$ids; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return array|null |
47
|
|
|
*/ |
48
|
|
|
public function findVids() |
49
|
|
|
{ |
50
|
|
|
return $this->vids; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param array|null $ids |
55
|
|
|
* @return $this |
56
|
|
|
*/ |
57
|
|
|
public function setVids(array $ids = null) |
58
|
|
|
{ |
59
|
|
|
$this->vids = $ids; |
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return array |
65
|
|
|
* @throws \Exception |
66
|
|
|
*/ |
67
|
|
|
public function getEmails(): array |
68
|
|
|
{ |
69
|
|
|
if (null === ($emails = $this->findEmails())) { |
70
|
|
|
throw new \Exception("Invalid Contact Emails"); |
71
|
|
|
} |
72
|
|
|
return (array)$emails; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return array|null |
77
|
|
|
*/ |
78
|
|
|
public function findEmails() |
79
|
|
|
{ |
80
|
|
|
return $this->emails; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param array|null $emails |
85
|
|
|
* @return $this |
86
|
|
|
*/ |
87
|
|
|
public function setEmails(array $emails = null) |
88
|
|
|
{ |
89
|
|
|
$this->emails = $emails; |
90
|
|
|
return $this; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return array |
95
|
|
|
* @throws \Exception |
96
|
|
|
*/ |
97
|
|
|
public function getPayload(): array |
98
|
|
|
{ |
99
|
|
|
return array_filter( |
100
|
|
|
[ |
101
|
|
|
'vids' => array_filter($this->getVids()), |
102
|
|
|
'emails' => array_filter($this->getEmails()) |
103
|
|
|
] |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param array $criteria |
109
|
|
|
* @param array $config |
110
|
|
|
* @return ResponseInterface |
111
|
|
|
* @throws \Exception |
112
|
|
|
*/ |
113
|
|
|
public function all(array $criteria = [], array $config = []): ResponseInterface |
114
|
|
|
{ |
115
|
|
|
$this->populate($criteria); |
116
|
|
|
|
117
|
|
|
return ContactListContacts::all( |
118
|
|
|
$this->getId(), |
119
|
|
|
$this->getConnection(), |
120
|
|
|
$this->getCache(), |
121
|
|
|
$this->getLogger(), |
122
|
|
|
$config |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param array $criteria |
128
|
|
|
* @param array $config |
129
|
|
|
* @return ResponseInterface |
130
|
|
|
* @throws \Exception |
131
|
|
|
*/ |
132
|
|
|
public function add(array $criteria = [], array $config = []): ResponseInterface |
133
|
|
|
{ |
134
|
|
|
$this->populate($criteria); |
135
|
|
|
|
136
|
|
|
return ContactListContacts::add( |
137
|
|
|
$this->getId(), |
138
|
|
|
$this->getPayload(), |
139
|
|
|
$this->getConnection(), |
140
|
|
|
$this->getCache(), |
141
|
|
|
$this->getLogger(), |
142
|
|
|
$config |
143
|
|
|
); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param array $criteria |
148
|
|
|
* @param array $config |
149
|
|
|
* @return ResponseInterface |
150
|
|
|
* @throws \Exception |
151
|
|
|
*/ |
152
|
|
|
public function remove(array $criteria = [], array $config = []): ResponseInterface |
153
|
|
|
{ |
154
|
|
|
$this->populate($criteria); |
155
|
|
|
|
156
|
|
|
return ContactListContacts::remove( |
157
|
|
|
$this->getId(), |
158
|
|
|
$this->getPayload(), |
159
|
|
|
$this->getConnection(), |
160
|
|
|
$this->getCache(), |
161
|
|
|
$this->getLogger(), |
162
|
|
|
$config |
163
|
|
|
); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|