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
|
|
|
$builder = new Read( |
71
|
|
|
$connection->getAppId(), |
|
|
|
|
72
|
|
|
$typeId, |
73
|
|
|
$id, |
74
|
|
|
$connection ?: HubSpot::getIntegrationConnection(), |
75
|
|
|
$cache ?: HubSpot::getCache(), |
76
|
|
|
$logger ?: HubSpot::getLogger(), |
77
|
|
|
$config |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
return $builder->build(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
|
85
|
|
|
/******************************************* |
86
|
|
|
* UPSERT |
87
|
|
|
*******************************************/ |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param string $typeId |
91
|
|
|
* @param string $id |
92
|
|
|
* @param array $payload |
93
|
|
|
* @param IntegrationConnectionInterface|null $connection |
94
|
|
|
* @param CacheInterface|null $cache |
95
|
|
|
* @param LoggerInterface|null $logger |
96
|
|
|
* @param array $config |
97
|
|
|
* @return ResponseInterface |
98
|
|
|
*/ |
99
|
|
|
public static function upsert( |
100
|
|
|
string $typeId, |
101
|
|
|
string $id, |
102
|
|
|
array $payload, |
103
|
|
|
IntegrationConnectionInterface $connection = null, |
104
|
|
|
CacheInterface $cache = null, |
105
|
|
|
LoggerInterface $logger = null, |
106
|
|
|
array $config = [] |
107
|
|
|
): ResponseInterface { |
108
|
|
|
return static::upsertRelay( |
109
|
|
|
$typeId, |
110
|
|
|
$id, |
111
|
|
|
$payload, |
112
|
|
|
$connection, |
113
|
|
|
$cache, |
114
|
|
|
$logger, |
115
|
|
|
$config |
116
|
|
|
)(); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param string $typeId |
121
|
|
|
* @param string $id |
122
|
|
|
* @param array $payload |
123
|
|
|
* @param IntegrationConnectionInterface|null $connection |
124
|
|
|
* @param CacheInterface|null $cache |
125
|
|
|
* @param LoggerInterface|null $logger |
126
|
|
|
* @param array $config |
127
|
|
|
* @return callable |
128
|
|
|
*/ |
129
|
|
|
public static function upsertRelay( |
130
|
|
|
string $typeId, |
131
|
|
|
string $id, |
132
|
|
|
array $payload, |
133
|
|
|
IntegrationConnectionInterface $connection = null, |
134
|
|
|
CacheInterface $cache = null, |
135
|
|
|
LoggerInterface $logger = null, |
136
|
|
|
array $config = [] |
137
|
|
|
): callable { |
138
|
|
|
|
139
|
|
|
$payload['id'] = $id; |
140
|
|
|
$payload['eventTypeId'] = $typeId; |
141
|
|
|
|
142
|
|
|
$builder = new Upsert( |
143
|
|
|
$connection->getAppId(), |
|
|
|
|
144
|
|
|
$typeId, |
145
|
|
|
$id, |
146
|
|
|
$payload, |
147
|
|
|
$connection ?: HubSpot::getIntegrationConnection(), |
148
|
|
|
$cache ?: HubSpot::getCache(), |
149
|
|
|
$logger ?: HubSpot::getLogger(), |
150
|
|
|
$config |
151
|
|
|
); |
152
|
|
|
|
153
|
|
|
return $builder->build(); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
/******************************************* |
158
|
|
|
* BATCH |
159
|
|
|
*******************************************/ |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @param array $payload |
163
|
|
|
* @param IntegrationConnectionInterface|null $connection |
164
|
|
|
* @param LoggerInterface|null $logger |
165
|
|
|
* @param array $config |
166
|
|
|
* @return ResponseInterface |
167
|
|
|
*/ |
168
|
|
|
public static function batch( |
169
|
|
|
array $payload, |
170
|
|
|
IntegrationConnectionInterface $connection = null, |
171
|
|
|
LoggerInterface $logger = null, |
172
|
|
|
array $config = [] |
173
|
|
|
): ResponseInterface { |
174
|
|
|
return static::batchRelay( |
175
|
|
|
$payload, |
176
|
|
|
$connection, |
177
|
|
|
$logger, |
178
|
|
|
$config |
179
|
|
|
)(); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @param array $payload |
184
|
|
|
* @param IntegrationConnectionInterface|null $connection |
185
|
|
|
* @param LoggerInterface|null $logger |
186
|
|
|
* @param array $config |
187
|
|
|
* @return callable |
188
|
|
|
*/ |
189
|
|
|
public static function batchRelay( |
190
|
|
|
array $payload, |
191
|
|
|
IntegrationConnectionInterface $connection = null, |
192
|
|
|
LoggerInterface $logger = null, |
193
|
|
|
array $config = [] |
194
|
|
|
): callable { |
195
|
|
|
|
196
|
|
|
$builder = new Batch( |
197
|
|
|
$connection->getAppId(), |
|
|
|
|
198
|
|
|
$payload, |
199
|
|
|
$connection ?: HubSpot::getIntegrationConnection(), |
200
|
|
|
$logger ?: HubSpot::getLogger(), |
201
|
|
|
$config |
202
|
|
|
); |
203
|
|
|
|
204
|
|
|
return $builder->build(); |
205
|
|
|
} |
206
|
|
|
} |
207
|
|
|
|
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: