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\Resources; |
10
|
|
|
|
11
|
|
|
use Flipbox\HubSpot\Connections\ConnectionInterface; |
12
|
|
|
use Flipbox\HubSpot\HubSpot; |
13
|
|
|
use Flipbox\Relay\HubSpot\Builder\Resources\Email\Subscription\ListTypes; |
14
|
|
|
use Flipbox\Relay\HubSpot\Builder\Resources\Email\Subscription\Read; |
15
|
|
|
use Flipbox\Relay\HubSpot\Builder\Resources\Email\Subscription\Update; |
16
|
|
|
use Psr\Http\Message\ResponseInterface; |
17
|
|
|
use Psr\Log\LoggerInterface; |
18
|
|
|
use Psr\SimpleCache\CacheInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Flipbox Factory <[email protected]> |
22
|
|
|
* @since 2.4.0 |
23
|
|
|
*/ |
24
|
|
|
class EmailSubscriptions |
25
|
|
|
{ |
26
|
|
|
/******************************************* |
27
|
|
|
* LIST |
28
|
|
|
*******************************************/ |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param ConnectionInterface|null $connection |
32
|
|
|
* @param LoggerInterface $logger |
33
|
|
|
* @param array $config |
34
|
|
|
* @return ResponseInterface |
35
|
|
|
*/ |
36
|
|
|
public static function list( |
37
|
|
|
ConnectionInterface $connection = null, |
38
|
|
|
CacheInterface $cache = null, |
39
|
|
|
LoggerInterface $logger = null, |
40
|
|
|
array $config = [] |
41
|
|
|
): ResponseInterface { |
42
|
|
|
return static::listRelay( |
43
|
|
|
$connection, |
44
|
|
|
$cache, |
45
|
|
|
$logger, |
46
|
|
|
$config |
47
|
|
|
)(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param ConnectionInterface|null $connection |
52
|
|
|
* @param LoggerInterface $logger |
53
|
|
|
* @param array $config |
54
|
|
|
* @return callable |
55
|
|
|
*/ |
56
|
|
|
public static function listRelay( |
57
|
|
|
ConnectionInterface $connection = null, |
58
|
|
|
CacheInterface $cache = null, |
59
|
|
|
LoggerInterface $logger = null, |
60
|
|
|
array $config = [] |
61
|
|
|
): callable { |
62
|
|
|
|
63
|
|
|
$builder = new ListTypes( |
64
|
|
|
$connection ?: HubSpot::getConnection(), |
65
|
|
|
$cache ?: HubSpot::getCache(), |
66
|
|
|
$logger ?: HubSpot::getLogger(), |
67
|
|
|
$config |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
return $builder->build(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
/******************************************* |
75
|
|
|
* READ BY EMAIL |
76
|
|
|
*******************************************/ |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string $email |
80
|
|
|
* @param ConnectionInterface|null $connection |
81
|
|
|
* @param CacheInterface|null $cache |
82
|
|
|
* @param LoggerInterface|null $logger |
83
|
|
|
* @param array $config |
84
|
|
|
* @return ResponseInterface |
85
|
|
|
*/ |
86
|
|
|
public static function read( |
87
|
|
|
string $email, |
88
|
|
|
ConnectionInterface $connection = null, |
89
|
|
|
CacheInterface $cache = null, |
90
|
|
|
LoggerInterface $logger = null, |
91
|
|
|
array $config = [] |
92
|
|
|
): ResponseInterface { |
93
|
|
|
return static::readRelay( |
94
|
|
|
$email, |
95
|
|
|
$connection, |
96
|
|
|
$cache, |
97
|
|
|
$logger, |
98
|
|
|
$config |
99
|
|
|
)(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param string $email |
104
|
|
|
* @param ConnectionInterface|null $connection |
105
|
|
|
* @param CacheInterface|null $cache |
106
|
|
|
* @param LoggerInterface|null $logger |
107
|
|
|
* @param array $config |
108
|
|
|
* @return callable |
109
|
|
|
*/ |
110
|
|
|
public static function readRelay( |
111
|
|
|
string $email, |
112
|
|
|
ConnectionInterface $connection = null, |
113
|
|
|
CacheInterface $cache = null, |
114
|
|
|
LoggerInterface $logger = null, |
115
|
|
|
array $config = [] |
116
|
|
|
): callable { |
117
|
|
|
|
118
|
|
|
$builder = new Read( |
119
|
|
|
$email, |
120
|
|
|
$connection ?: HubSpot::getConnection(), |
121
|
|
|
$cache ?: HubSpot::getCache(), |
122
|
|
|
$logger ?: HubSpot::getLogger(), |
123
|
|
|
$config |
124
|
|
|
); |
125
|
|
|
|
126
|
|
|
return $builder->build(); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/******************************************* |
130
|
|
|
* UPDATE |
131
|
|
|
*******************************************/ |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param string $email |
135
|
|
|
* @param array $payload |
136
|
|
|
* @param ConnectionInterface|null $connection |
137
|
|
|
* @param CacheInterface|null $cache |
138
|
|
|
* @param LoggerInterface|null $logger |
139
|
|
|
* @param array $config |
140
|
|
|
* @return ResponseInterface |
141
|
|
|
*/ |
142
|
|
|
public static function update( |
143
|
|
|
string $email, |
144
|
|
|
array $payload, |
145
|
|
|
ConnectionInterface $connection = null, |
146
|
|
|
CacheInterface $cache = null, |
147
|
|
|
LoggerInterface $logger = null, |
148
|
|
|
array $config = [] |
149
|
|
|
): ResponseInterface { |
150
|
|
|
return static::updateRelay( |
151
|
|
|
$email, |
152
|
|
|
$payload, |
153
|
|
|
$connection, |
154
|
|
|
$cache, |
155
|
|
|
$logger, |
156
|
|
|
$config |
157
|
|
|
)(); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param string $email |
162
|
|
|
* @param array $payload |
163
|
|
|
* @param ConnectionInterface|null $connection |
164
|
|
|
* @param CacheInterface|null $cache |
165
|
|
|
* @param LoggerInterface|null $logger |
166
|
|
|
* @param array $config |
167
|
|
|
* @return callable |
168
|
|
|
*/ |
169
|
|
|
public static function updateRelay( |
170
|
|
|
string $email, |
171
|
|
|
array $payload, |
172
|
|
|
ConnectionInterface $connection = null, |
173
|
|
|
CacheInterface $cache = null, |
174
|
|
|
LoggerInterface $logger = null, |
175
|
|
|
array $config = [] |
176
|
|
|
): callable { |
177
|
|
|
|
178
|
|
|
$builder = new Update( |
179
|
|
|
$email, |
180
|
|
|
$payload, |
181
|
|
|
$connection ?: HubSpot::getConnection(), |
182
|
|
|
$cache ?: HubSpot::getCache(), |
183
|
|
|
$logger ?: HubSpot::getLogger(), |
184
|
|
|
$config |
185
|
|
|
); |
186
|
|
|
|
187
|
|
|
return $builder->build(); |
188
|
|
|
} |
189
|
|
|
} |
190
|
|
|
|