|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SevenShores\Hubspot\Resources; |
|
4
|
|
|
|
|
5
|
|
|
class Timeline extends Resource |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* Create or Update Timeline Event |
|
9
|
|
|
* |
|
10
|
|
|
* @param int $appId |
|
11
|
|
|
* @param int $eventTypeId |
|
12
|
|
|
* @param string $id |
|
13
|
|
|
* @param int|null $objectId |
|
14
|
|
|
* @param string|null $email |
|
15
|
|
|
* @param string|null $utk |
|
16
|
|
|
* @param array $extraData |
|
17
|
|
|
* @param mixed $timestamp |
|
18
|
|
|
* @param array $eventTypeData |
|
19
|
|
|
* |
|
20
|
|
|
* @return mixed |
|
21
|
|
|
* |
|
22
|
|
|
* @see http://developers.hubspot.com/docs/methods/timeline/create-or-update-event |
|
23
|
|
|
*/ |
|
24
|
|
|
public function createOrUpdate( |
|
25
|
|
|
$appId, |
|
26
|
|
|
$eventTypeId, |
|
27
|
|
|
$id, |
|
28
|
|
|
$objectId = null, |
|
29
|
|
|
$email = null, |
|
30
|
|
|
$utk = null, |
|
31
|
|
|
$extraData = [], |
|
32
|
|
|
$timestamp = null, |
|
33
|
|
|
$eventTypeData = [] |
|
34
|
|
|
) { |
|
35
|
|
|
$endpoint = "https://api.hubapi.com/integrations/v1/{$appId}/timeline/event"; |
|
36
|
|
|
|
|
37
|
|
|
$data['json'] = array_merge([ |
|
|
|
|
|
|
38
|
|
|
'eventTypeId' => $eventTypeId, |
|
39
|
|
|
'id' => $id, |
|
40
|
|
|
'objectId' => $objectId, |
|
41
|
|
|
'email' => $email, |
|
42
|
|
|
'utk' => $utk, |
|
43
|
|
|
'extraData' => $extraData, |
|
44
|
|
|
'timestamp' => $this->timestamp($timestamp), |
|
45
|
|
|
], $eventTypeData); |
|
46
|
|
|
|
|
47
|
|
|
return $this->client->request('put', $endpoint, $data); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Batch Create or Update Timeline Events |
|
52
|
|
|
* |
|
53
|
|
|
* @param int $appId |
|
54
|
|
|
* @param array $events |
|
55
|
|
|
* |
|
56
|
|
|
* @return mixed |
|
57
|
|
|
* |
|
58
|
|
|
* @see https://developers.hubspot.com/docs/methods/timeline/batch-create-or-update-events |
|
59
|
|
|
*/ |
|
60
|
|
|
public function createOrUpdateBatch($appId,$events=[]) |
|
61
|
|
|
{ |
|
62
|
|
|
$endpoint = "https://api.hubapi.com/integrations/v1/{$appId}/timeline/event/batch"; |
|
63
|
|
|
|
|
64
|
|
|
$data['json'] = ['eventWrappers' => $events]; |
|
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
return $this->client->request('put', $endpoint, $data); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Get Timeline Event Types |
|
71
|
|
|
* |
|
72
|
|
|
* @param int $appId |
|
73
|
|
|
* |
|
74
|
|
|
* @return mixed |
|
75
|
|
|
* |
|
76
|
|
|
* @see http://developers.hubspot.com/docs/methods/timeline/get-event-types |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getEventTypes($appId) |
|
79
|
|
|
{ |
|
80
|
|
|
$endpoint = "https://api.hubapi.com/integrations/v1/{$appId}/timeline/event-types"; |
|
81
|
|
|
return $this->client->request('get', $endpoint); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Create Timeline Event Type |
|
86
|
|
|
* |
|
87
|
|
|
* @param int $appId |
|
88
|
|
|
* @param string $name |
|
89
|
|
|
* @param string|null $headerTemplate |
|
90
|
|
|
* @param string|null $detailTemplate |
|
91
|
|
|
* @param string|null $objectType |
|
92
|
|
|
* |
|
93
|
|
|
* @return mixed |
|
94
|
|
|
* |
|
95
|
|
|
* @see http://developers.hubspot.com/docs/methods/timeline/create-event-type |
|
96
|
|
|
*/ |
|
97
|
|
View Code Duplication |
public function createEventType( |
|
98
|
|
|
$appId, |
|
99
|
|
|
$name, |
|
100
|
|
|
$headerTemplate = null, |
|
101
|
|
|
$detailTemplate = null, |
|
102
|
|
|
$objectType = null |
|
103
|
|
|
) { |
|
104
|
|
|
$endpoint = "https://api.hubapi.com/integrations/v1/{$appId}/timeline/event-types"; |
|
105
|
|
|
|
|
106
|
|
|
$data['json'] = [ |
|
|
|
|
|
|
107
|
|
|
'applicationId' => $appId, |
|
108
|
|
|
'name' => $name, |
|
109
|
|
|
'headerTemplate' => $headerTemplate, |
|
110
|
|
|
'detailTemplate' => $detailTemplate, |
|
111
|
|
|
'objectType' => $objectType, |
|
112
|
|
|
]; |
|
113
|
|
|
|
|
114
|
|
|
return $this->client->request('post', $endpoint, $data); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Update Timeline Event Type |
|
119
|
|
|
* |
|
120
|
|
|
* @param int $appId |
|
121
|
|
|
* @param int $eventTypeId |
|
122
|
|
|
* @param string|null $name |
|
123
|
|
|
* @param string|null $headerTemplate |
|
124
|
|
|
* @param string|null $detailTemplate |
|
125
|
|
|
* @param string|null $objectType |
|
126
|
|
|
* |
|
127
|
|
|
* @return mixed |
|
128
|
|
|
* |
|
129
|
|
|
* @see http://developers.hubspot.com/docs/methods/timeline/update-event-type |
|
130
|
|
|
*/ |
|
131
|
|
View Code Duplication |
public function updateEventType( |
|
132
|
|
|
$appId, |
|
133
|
|
|
$eventTypeId, |
|
134
|
|
|
$name = null, |
|
135
|
|
|
$headerTemplate = null, |
|
136
|
|
|
$detailTemplate = null, |
|
137
|
|
|
$objectType = null |
|
138
|
|
|
) { |
|
139
|
|
|
$endpoint = "https://api.hubapi.com/integrations/v1/{$appId}/timeline/event-types/{$eventTypeId}"; |
|
140
|
|
|
|
|
141
|
|
|
$data['json'] = [ |
|
|
|
|
|
|
142
|
|
|
'applicationId' => $appId, |
|
143
|
|
|
'name' => $name, |
|
144
|
|
|
'headerTemplate' => $headerTemplate, |
|
145
|
|
|
'detailTemplate' => $detailTemplate, |
|
146
|
|
|
'objectType' => $objectType, |
|
147
|
|
|
]; |
|
148
|
|
|
|
|
149
|
|
|
return $this->client->request('put', $endpoint, $data); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Delete Timeline Event Type |
|
154
|
|
|
* |
|
155
|
|
|
* @param int $appId |
|
156
|
|
|
* @param int $eventTypeId |
|
157
|
|
|
* |
|
158
|
|
|
* @return mixed |
|
159
|
|
|
* |
|
160
|
|
|
* @see http://developers.hubspot.com/docs/methods/timeline/delete-event-type |
|
161
|
|
|
*/ |
|
162
|
|
|
public function deleteEventType($appId, $eventTypeId) |
|
163
|
|
|
{ |
|
164
|
|
|
$endpoint = "https://api.hubapi.com/integrations/v1/{$appId}/timeline/event-types/{$eventTypeId}"; |
|
165
|
|
|
return $this->client->request('delete', $endpoint); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Get Properties for Timeline Event Type |
|
170
|
|
|
* |
|
171
|
|
|
* @param int $appId |
|
172
|
|
|
* @param int $eventTypeId |
|
173
|
|
|
* |
|
174
|
|
|
* @return mixed |
|
175
|
|
|
* |
|
176
|
|
|
* @see http://developers.hubspot.com/docs/methods/timeline/get-timeline-event-type-properties |
|
177
|
|
|
*/ |
|
178
|
|
|
public function getEventTypeProperties($appId, $eventTypeId) |
|
179
|
|
|
{ |
|
180
|
|
|
$endpoint = "https://api.hubapi.com/integrations/v1/{$appId}/timeline/event-types/{$eventTypeId}/properties"; |
|
181
|
|
|
return $this->client->request('get', $endpoint); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* Create Property for Timeline Event Type |
|
186
|
|
|
* |
|
187
|
|
|
* @param int $appId |
|
188
|
|
|
* @param int $eventTypeId |
|
189
|
|
|
* @param string $name |
|
190
|
|
|
* @param string $label |
|
191
|
|
|
* @param string $propertyType |
|
192
|
|
|
* @param string|null $objectProperty |
|
193
|
|
|
* @param array $options |
|
194
|
|
|
* |
|
195
|
|
|
* @return mixed |
|
196
|
|
|
* |
|
197
|
|
|
* @see http://developers.hubspot.com/docs/methods/timeline/create-timeline-event-type-property |
|
198
|
|
|
*/ |
|
199
|
|
|
public function createEventTypeProperty( |
|
200
|
|
|
$appId, |
|
201
|
|
|
$eventTypeId, |
|
202
|
|
|
$name, |
|
203
|
|
|
$label, |
|
204
|
|
|
$propertyType, |
|
205
|
|
|
$objectProperty = null, |
|
206
|
|
|
$options = [] |
|
207
|
|
|
) { |
|
208
|
|
|
$endpoint = "https://api.hubapi.com/integrations/v1/{$appId}/timeline/event-types/{$eventTypeId}/properties"; |
|
209
|
|
|
|
|
210
|
|
|
$data['json'] = [ |
|
|
|
|
|
|
211
|
|
|
'name' => $name, |
|
212
|
|
|
'label' => $label, |
|
213
|
|
|
'propertyType' => $propertyType, |
|
214
|
|
|
'objectProperty' => $objectProperty, |
|
215
|
|
|
'options' => $options, |
|
216
|
|
|
]; |
|
217
|
|
|
|
|
218
|
|
|
return $this->client->request('post', $endpoint, $data); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* Update Property for Timeline Event Type |
|
223
|
|
|
* |
|
224
|
|
|
* @param int $appId |
|
225
|
|
|
* @param int $eventTypeId |
|
226
|
|
|
* @param int $eventTypePropertyId |
|
227
|
|
|
* @param string $name |
|
228
|
|
|
* @param string $label |
|
229
|
|
|
* @param string $propertyType |
|
230
|
|
|
* @param array|null $options |
|
231
|
|
|
* |
|
232
|
|
|
* @return mixed |
|
233
|
|
|
* |
|
234
|
|
|
* @see http://developers.hubspot.com/docs/methods/timeline/udpate-timeline-event-type-property |
|
235
|
|
|
*/ |
|
236
|
|
|
public function updateEventTypeProperty( |
|
237
|
|
|
$appId, |
|
238
|
|
|
$eventTypeId, |
|
239
|
|
|
$eventTypePropertyId, |
|
240
|
|
|
$name, |
|
241
|
|
|
$label, |
|
242
|
|
|
$propertyType, |
|
243
|
|
|
$options = null |
|
244
|
|
|
) { |
|
245
|
|
|
$endpoint = "https://api.hubapi.com/integrations/v1/{$appId}/timeline/event-types/{$eventTypeId}/properties"; |
|
246
|
|
|
|
|
247
|
|
|
$data['json'] = [ |
|
|
|
|
|
|
248
|
|
|
'id' => $eventTypePropertyId, |
|
249
|
|
|
'name' => $name, |
|
250
|
|
|
'label' => $label, |
|
251
|
|
|
'propertyType' => $propertyType, |
|
252
|
|
|
]; |
|
253
|
|
|
|
|
254
|
|
|
if (isset($options)) { |
|
255
|
|
|
$data['json']['options'] = $options; |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
return $this->client->request('put', $endpoint, $data); |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* Delete Property for Timeline Event Type |
|
263
|
|
|
* |
|
264
|
|
|
* @param int $appId |
|
265
|
|
|
* @param int $eventTypeId |
|
266
|
|
|
* @param int $eventTypePropertyId |
|
267
|
|
|
* |
|
268
|
|
|
* @return mixed |
|
269
|
|
|
* |
|
270
|
|
|
* @see http://developers.hubspot.com/docs/methods/timeline/delete-timeline-event-type-property |
|
271
|
|
|
*/ |
|
272
|
|
|
public function deleteEventTypeProperty($appId, $eventTypeId, $eventTypePropertyId) |
|
273
|
|
|
{ |
|
274
|
|
|
$endpoint = "https://api.hubapi.com/integrations/v1/{$appId}/timeline/event-types/{$eventTypeId}/properties/{$eventTypePropertyId}"; |
|
275
|
|
|
return $this->client->request('delete', $endpoint); |
|
276
|
|
|
} |
|
277
|
|
|
} |
|
278
|
|
|
|
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.