|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SevenShores\Hubspot\Resources; |
|
4
|
|
|
|
|
5
|
|
|
use SevenShores\Hubspot\Exceptions\BadRequest; |
|
6
|
|
|
|
|
7
|
|
|
class Engagements extends Resource |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @param array $engagement Array of engagement engagement. |
|
11
|
|
|
* @param array $associations Array of engagement associations. |
|
12
|
|
|
* @param array $metadata Array of engagement metadata. |
|
13
|
|
|
* @param array $attachments Array of engagement attachments. |
|
14
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
15
|
|
|
*/ |
|
16
|
|
|
function create($engagement, $associations, $metadata, $attachments = array()) |
|
|
|
|
|
|
17
|
|
|
{ |
|
18
|
|
|
$endpoint = "https://api.hubapi.com/engagements/v1/engagements"; |
|
19
|
|
|
|
|
20
|
|
|
$options['json'] = [ |
|
|
|
|
|
|
21
|
|
|
'engagement' => $engagement, |
|
22
|
|
|
'associations' => $associations, |
|
23
|
|
|
'metadata' => $metadata, |
|
24
|
|
|
'attachments' => $attachments |
|
25
|
|
|
]; |
|
26
|
|
|
|
|
27
|
|
|
return $this->client->request('post', $endpoint, $options); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Returns all recently created or updated engagements. |
|
32
|
|
|
* |
|
33
|
|
|
* @param array $params Array of optional parameters ['count', 'offset', 'since] |
|
34
|
|
|
* |
|
35
|
|
|
* @see https://developers.hubspot.com/docs/methods/engagements/get-recent-engagements |
|
36
|
|
|
* |
|
37
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
38
|
|
|
*/ |
|
39
|
|
|
function recent($params = []) |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
$endpoint = 'https://api.hubapi.com/engagements/v1/engagements/recent/modified'; |
|
42
|
|
|
|
|
43
|
|
|
$queryString = build_query_string($params); |
|
44
|
|
|
|
|
45
|
|
|
return $this->client->request('get', $endpoint, [], $queryString); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param int $id The engagement id. |
|
50
|
|
|
* @param array $engagement The engagement engagement to update. |
|
51
|
|
|
* @param array $metadata The engagement metadata to update. |
|
52
|
|
|
* @param string $method |
|
53
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
54
|
|
|
* @throws \SevenShores\Hubspot\Exceptions\BadRequest |
|
55
|
|
|
*/ |
|
56
|
|
|
function update($id, $engagement, $metadata, $method = 'patch') |
|
|
|
|
|
|
57
|
|
|
{ |
|
58
|
|
|
$availableMethods = ['put', 'patch']; |
|
59
|
|
|
|
|
60
|
|
|
if (! \in_array($method, $availableMethods)) { |
|
61
|
|
|
throw new BadRequest('Method name '.$method.' is invalid', 400); |
|
62
|
|
|
} |
|
63
|
|
|
$endpoint = "https://api.hubapi.com/engagements/v1/engagements/{$id}"; |
|
64
|
|
|
|
|
65
|
|
|
$options['json'] = [ |
|
|
|
|
|
|
66
|
|
|
'engagement' => $engagement, |
|
67
|
|
|
'metadata' => $metadata, |
|
68
|
|
|
]; |
|
69
|
|
|
|
|
70
|
|
|
return $this->client->request($method, $endpoint, $options); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param int $id |
|
75
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
76
|
|
|
*/ |
|
77
|
|
|
function delete($id) |
|
|
|
|
|
|
78
|
|
|
{ |
|
79
|
|
|
$endpoint = "https://api.hubapi.com/engagements/v1/engagements/{$id}"; |
|
80
|
|
|
|
|
81
|
|
|
return $this->client->request('delete', $endpoint); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param int $id |
|
86
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
87
|
|
|
*/ |
|
88
|
|
|
function get($id) |
|
|
|
|
|
|
89
|
|
|
{ |
|
90
|
|
|
$endpoint = "https://api.hubapi.com/engagements/v1/engagements/{$id}"; |
|
91
|
|
|
|
|
92
|
|
|
return $this->client->request('get', $endpoint); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Returns all engagements. |
|
97
|
|
|
* |
|
98
|
|
|
* @param array $params Array of optional parameters ['limit', 'offset'] |
|
99
|
|
|
* |
|
100
|
|
|
* @see http://developers.hubspot.com/docs/methods/engagements/get-all-engagements |
|
101
|
|
|
* |
|
102
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
103
|
|
|
*/ |
|
104
|
|
|
public function all($params = []) |
|
105
|
|
|
{ |
|
106
|
|
|
$endpoint = 'https://api.hubapi.com/engagements/v1/engagements/paged'; |
|
107
|
|
|
|
|
108
|
|
|
$queryString = build_query_string($params); |
|
109
|
|
|
|
|
110
|
|
|
return $this->client->request('get', $endpoint, [], $queryString); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @param int $id |
|
115
|
|
|
* @param string $object_type |
|
116
|
|
|
* @param int $object_id |
|
117
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
118
|
|
|
**/ |
|
119
|
|
|
function associate($id, $object_type, $object_id) |
|
|
|
|
|
|
120
|
|
|
{ |
|
121
|
|
|
$endpoint = "https://api.hubapi.com/engagements/v1/engagements/{$id}/associations/{$object_type}/{$object_id}"; |
|
122
|
|
|
|
|
123
|
|
|
return $this->client->request('put', $endpoint); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @param string $object_type |
|
128
|
|
|
* @param int $object_id |
|
129
|
|
|
* @param array $params Array of optional parameters ['limit', 'offset'] |
|
130
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
131
|
|
|
**/ |
|
132
|
|
|
function associated($object_type, $object_id, $params = []) |
|
|
|
|
|
|
133
|
|
|
{ |
|
134
|
|
|
$endpoint = "https://api.hubapi.com/engagements/v1/engagements/associated/{$object_type}/{$object_id}/paged"; |
|
135
|
|
|
$queryString = build_query_string($params); |
|
136
|
|
|
return $this->client->request('get', $endpoint, [], $queryString); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @return \SevenShores\Hubspot\Http\Response |
|
141
|
|
|
*/ |
|
142
|
|
|
function activityTypes() |
|
|
|
|
|
|
143
|
|
|
{ |
|
144
|
|
|
$endpoint = "https://api.hubapi.com/engagements/v1/activity-types"; |
|
145
|
|
|
|
|
146
|
|
|
return $this->client->request('get', $endpoint); |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.