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\IntegrationConnectionInterface; |
12
|
|
|
use Flipbox\HubSpot\HubSpot; |
13
|
|
|
use Flipbox\Relay\HubSpot\Builder\Resources\Timeline\Event\Batch; |
14
|
|
|
use Flipbox\Relay\HubSpot\Builder\Resources\Timeline\Event\Read; |
15
|
|
|
use Flipbox\Relay\HubSpot\Builder\Resources\Timeline\Event\Upsert; |
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.0.0 |
23
|
|
|
*/ |
24
|
|
|
class TimelineEvent |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @param string $id |
28
|
|
|
* @param string $typeId |
29
|
|
|
* @param IntegrationConnectionInterface|null $connection |
30
|
|
|
* @param CacheInterface|null $cache |
31
|
|
|
* @param LoggerInterface|null $logger |
32
|
|
|
* @param array $config |
33
|
|
|
* @return ResponseInterface |
34
|
|
|
*/ |
35
|
|
|
public static function read( |
36
|
|
|
string $id, |
37
|
|
|
string $typeId, |
38
|
|
|
IntegrationConnectionInterface $connection = null, |
39
|
|
|
CacheInterface $cache = null, |
40
|
|
|
LoggerInterface $logger = null, |
41
|
|
|
array $config = [] |
42
|
|
|
): ResponseInterface { |
43
|
|
|
return static::readRelay( |
44
|
|
|
$id, |
45
|
|
|
$typeId, |
46
|
|
|
$connection, |
47
|
|
|
$cache, |
48
|
|
|
$logger, |
49
|
|
|
$config |
50
|
|
|
)(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $id |
55
|
|
|
* @param string $typeId |
56
|
|
|
* @param IntegrationConnectionInterface|null $connection |
57
|
|
|
* @param CacheInterface|null $cache |
58
|
|
|
* @param LoggerInterface|null $logger |
59
|
|
|
* @param array $config |
60
|
|
|
* @return callable |
61
|
|
|
*/ |
62
|
|
|
public static function readRelay( |
63
|
|
|
string $id, |
64
|
|
|
string $typeId, |
65
|
|
|
IntegrationConnectionInterface $connection = null, |
66
|
|
|
CacheInterface $cache = null, |
67
|
|
|
LoggerInterface $logger = null, |
68
|
|
|
array $config = [] |
69
|
|
|
): callable { |
70
|
|
|
|
71
|
|
|
$connection = $connection ?: HubSpot::getIntegrationConnection(); |
72
|
|
|
|
73
|
|
|
$builder = new Read( |
74
|
|
|
$connection->getAppId(), |
75
|
|
|
$typeId, |
76
|
|
|
$id, |
77
|
|
|
$connection, |
78
|
|
|
$cache ?: HubSpot::getCache(), |
79
|
|
|
$logger ?: HubSpot::getLogger(), |
80
|
|
|
$config |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
return $builder->build(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
|
88
|
|
|
/******************************************* |
89
|
|
|
* UPSERT |
90
|
|
|
*******************************************/ |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param string $typeId |
94
|
|
|
* @param string $id |
95
|
|
|
* @param array $payload |
96
|
|
|
* @param IntegrationConnectionInterface|null $connection |
97
|
|
|
* @param CacheInterface|null $cache |
98
|
|
|
* @param LoggerInterface|null $logger |
99
|
|
|
* @param array $config |
100
|
|
|
* @return ResponseInterface |
101
|
|
|
*/ |
102
|
|
|
public static function upsert( |
103
|
|
|
string $id, |
104
|
|
|
string $typeId, |
105
|
|
|
array $payload, |
106
|
|
|
IntegrationConnectionInterface $connection = null, |
107
|
|
|
CacheInterface $cache = null, |
108
|
|
|
LoggerInterface $logger = null, |
109
|
|
|
array $config = [] |
110
|
|
|
): ResponseInterface { |
111
|
|
|
return static::upsertRelay( |
112
|
|
|
$id, |
113
|
|
|
$typeId, |
114
|
|
|
$payload, |
115
|
|
|
$connection, |
116
|
|
|
$cache, |
117
|
|
|
$logger, |
118
|
|
|
$config |
119
|
|
|
)(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param string $typeId |
124
|
|
|
* @param string $id |
125
|
|
|
* @param array $payload |
126
|
|
|
* @param IntegrationConnectionInterface|null $connection |
127
|
|
|
* @param CacheInterface|null $cache |
128
|
|
|
* @param LoggerInterface|null $logger |
129
|
|
|
* @param array $config |
130
|
|
|
* @return callable |
131
|
|
|
*/ |
132
|
|
|
public static function upsertRelay( |
133
|
|
|
string $id, |
134
|
|
|
string $typeId, |
135
|
|
|
array $payload, |
136
|
|
|
IntegrationConnectionInterface $connection = null, |
137
|
|
|
CacheInterface $cache = null, |
138
|
|
|
LoggerInterface $logger = null, |
139
|
|
|
array $config = [] |
140
|
|
|
): callable { |
141
|
|
|
|
142
|
|
|
$payload['id'] = $id; |
143
|
|
|
$payload['eventTypeId'] = $typeId; |
144
|
|
|
|
145
|
|
|
$connection = $connection ?: HubSpot::getIntegrationConnection(); |
146
|
|
|
|
147
|
|
|
$builder = new Upsert( |
148
|
|
|
$connection->getAppId(), |
149
|
|
|
$typeId, |
150
|
|
|
$id, |
151
|
|
|
$payload, |
152
|
|
|
$connection, |
153
|
|
|
$cache ?: HubSpot::getCache(), |
154
|
|
|
$logger ?: HubSpot::getLogger(), |
155
|
|
|
$config |
156
|
|
|
); |
157
|
|
|
|
158
|
|
|
return $builder->build(); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
|
162
|
|
|
/******************************************* |
163
|
|
|
* BATCH |
164
|
|
|
*******************************************/ |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @param array $payload |
168
|
|
|
* @param IntegrationConnectionInterface|null $connection |
169
|
|
|
* @param LoggerInterface|null $logger |
170
|
|
|
* @param array $config |
171
|
|
|
* @return ResponseInterface |
172
|
|
|
*/ |
173
|
|
|
public static function batch( |
174
|
|
|
array $payload, |
175
|
|
|
IntegrationConnectionInterface $connection = null, |
176
|
|
|
LoggerInterface $logger = null, |
177
|
|
|
array $config = [] |
178
|
|
|
): ResponseInterface { |
179
|
|
|
return static::batchRelay( |
180
|
|
|
$payload, |
181
|
|
|
$connection, |
182
|
|
|
$logger, |
183
|
|
|
$config |
184
|
|
|
)(); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @param array $payload |
189
|
|
|
* @param IntegrationConnectionInterface|null $connection |
190
|
|
|
* @param LoggerInterface|null $logger |
191
|
|
|
* @param array $config |
192
|
|
|
* @return callable |
193
|
|
|
*/ |
194
|
|
|
public static function batchRelay( |
195
|
|
|
array $payload, |
196
|
|
|
IntegrationConnectionInterface $connection = null, |
197
|
|
|
LoggerInterface $logger = null, |
198
|
|
|
array $config = [] |
199
|
|
|
): callable { |
200
|
|
|
$connection = $connection ?: HubSpot::getIntegrationConnection(); |
201
|
|
|
|
202
|
|
|
$builder = new Batch( |
203
|
|
|
$connection->getAppId(), |
204
|
|
|
$payload, |
205
|
|
|
$connection, |
206
|
|
|
$logger ?: HubSpot::getLogger(), |
207
|
|
|
$config |
208
|
|
|
); |
209
|
|
|
|
210
|
|
|
return $builder->build(); |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
|