-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathclass.lists.php
306 lines (286 loc) · 8.2 KB
/
class.lists.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<?php
/**
* Copyright 2013 HubSpot, Inc.
*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
require_once('class.baseclient.php');
class HubSpot_Lists extends HubSpot_Baseclient{
protected $API_PATH = 'contacts';
protected $API_VERSION = 'v1';
/**
* Create a new List
*
*@param params: Array of required and optional parameters for the list.
* This will include: name, dynamic (true/false), portalID, and an array of filters
*
* @return Response body from HTTP POST request
*
* @throws HubSpot_Exception
**/
public function create_list($params){
$endpoint = 'lists';
try{
return json_decode($this->execute_JSON_post_request($this->get_request_url($endpoint,null),json_encode($params)));
}
catch(HubSpot_Exception $e){
print_r("Unable to create list: ".$e);
}
}
/**
* Update a List
*
*@param params: Array of required and optional parameters for the list.
* This will include: name, dynamic (true/false), portalID, and an array of filters
* id: Unique ID of the list to update
*
* @return Response body from HTTP POST request
*
* @throws HubSpot_Exception
**/
public function update_list($id, $params){
$endpoint = 'lists/'.$id;
try{
return json_decode($this->execute_JSON_post_request($this->get_request_url($endpoint,null),json_encode($params)));
}
catch(HubSpot_Exception $e){
print_r("Unable to update list: ".$e);
}
}
/**
* Delete a List
*
*@param id: Unique ID of the list to delete
*
*
* @return Response body from HTTP POST request
*
* @throws HubSpot_Exception
**/
public function delete_list($id){
$endpoint = 'lists/'.$id;
try{
return json_decode($this->execute_delete_request($this->get_request_url($endpoint,null)));
}
catch(HubSpot_Exception $e){
print_r("Unable to delete list: ".$e);
}
}
/**
* Get a contact List by ID
*
*@param id: Unique ID of the list to retrieve
*
*
* @return JSON object for the requested List
*
* @throws HubSpot_Exception
**/
public function get_list($id){
$endpoint = 'lists/'.$id;
try{
return json_decode($this->execute_get_request($this->get_request_url($endpoint,null)));
}
catch(HubSpot_Exception $e){
print_r('Unable to retrieve list: '.$e);
}
}
/**
* Get all Lists
*
*@param params: Array of parameters for request URL
* count: number of lists to return
* offset: offset number at which to start the list query
* The list results will have a 'has-more' field which will indicate
* if there are more lists to be returned, as well as an 'offset' field
* to indicate where to start the next query if there are more results
*
*
* @return JSON objects for the requested Lists
*
* @throws HubSpot_Exception
**/
public function get_lists($params){
$endpoint = 'lists';
try{
return json_decode($this->execute_get_request($this->get_request_url($endpoint,$params)));
}
catch(HubSpot_Exception $e){
print_r('Unable to get lists: '.$e);
}
}
/**
* Get static Lists
*
*@param params: Array of parameters for request URL
* count: number of lists to return
* offset: offset number at which to start the list query
* The list results will have a 'has-more' field which will indicate
* if there are more lists to be returned, as well as an 'offset' field
* to indicate where to start the next query if there are more results
*
*
* @return JSON objects for the requested Lists
*
* @throws HubSpot_Exception
**/
public function get_static_lists($params){
$endpoint = 'lists/static';
try{
return json_decode($this->execute_get_request($this->get_request_url($endpoint,$params)));
}
catch(HubSpot_Exception $e){
print_r('Unable to get lists: '.$e);
}
}
/**
* Get dynamic Lists
*
*@param params: Array of parameters for request URL
* count: number of lists to return
* offset: offset number at which to start the list query
* The list results will have a 'has-more' field which will indicate
* if there are more lists to be returned, as well as an 'offset' field
* to indicate where to start the next query if there are more results
*
*
* @return JSON objects for the requested Lists
*
* @throws HubSpot_Exception
**/
public function get_dynamic_lists($params){
$endpoint = 'lists/dynamic';
try{
return json_decode($this->execute_get_request($this->get_request_url($endpoint,$params)));
}
catch(HubSpot_Exception $e){
print_r('Unable to get lists: '.$e);
}
}
/**
* Get Contacts in a List
*
*@param params: Array of parameters for request URL
* count: number of lists to return
* vidOffset: offset contact vid at which to start the query
* The results will have a 'has-more' field which will indicate
* if there are more contacts to be returned, as well as a 'vid-offset' field
* to indicate where to start the next query if there are more results
* property: Use this to return only one contact property in the results
* id: ID of the list to return
*
*
* @return JSON objects for the requested Contacts
*
* @throws HubSpot_Exception
**/
public function get_contacts_in_list($params, $id){
$endpoint = 'lists/'.$id.'/contacts/all';
try{
return json_decode($this->execute_get_request($this->get_request_url($endpoint,$params)));
}
catch(HubSpot_Exception $e){
print_r('Unable to get contacts: '.$e);
}
}
/**
* Get recently updated Contacts in a List
*
*@param params: Array of parameters for request URL
* count: number of lists to return
* timeOffset: time offset at which to start the query
* The results will have a 'has-more' field which will indicate
* if there are more contacts to be returned, as well as a 'time-offset' field
* to indicate where to start the next query if there are more results
* property: Use this to return only one contact property in the results
* id: ID of the list to return
*
*
* @return JSON objects for the requested Contacts
*
* @throws HubSpot_Exception
**/
public function get_recent_contacts_in_list($params, $id){
$endpoint = 'lists/'.$id.'/contacts/recent';
try{
return json_decode($this->execute_get_request($this->get_request_url($endpoint,$params)));
}
catch(HubSpot_Exception $e){
print_r('Unable to get contacts: '.$e);
}
}
/**
* Refresh a Contact List
*
*@param id: Unique ID of the list to refresh
*
*
* @return Resonse body from HTTP POST request
*
* @throws HubSpot_Exception
**/
public function refresh_list($id){
$endpoint = 'lists/'.$id.'/refresh';
try{
return $this->execute_post_request($this->get_request_url($endpoint,null),null);
}
catch(HubSpot_Exception $e){
print_r("Unable to refresh list: ".$e);
}
}
/**
* Add Contacts to static List
*
*@param vids: Unassociated array of vids for contacts to add to list
* id: ID of list to add contacts to
*
*
* @return Resonse body from HTTP POST request
*
* @throws HubSpot_Exception
**/
public function add_contacts_to_list($vids,$id){
$endpoint = 'lists/'.$id.'/add';
$request_body = array('vids'=>$vids);
try{
return $this->execute_JSON_post_request($this->get_request_url($endpoint,null),json_encode($request_body));
}
catch(HubSpot_Exception $e){
print_r("Unable to add contacts: ".$e);
}
}
/**
* Remove Contacts from static List
*
*@param vids: Unassociated array of vids for contacts to remove from
* id: ID of list to remove contacts from
*
*
* @return Resonse body from HTTP POST request
*
* @throws HubSpot_Exception
**/
public function remove_contacts_from_list($vids,$id){
$endpoint = 'lists/'.$id.'/remove';
$request_body = array('vids'=>$vids);
try{
return $this->execute_JSON_post_request($this->get_request_url($endpoint,null),json_encode($request_body));
}
catch(HubSpot_Exception $e){
print_r("Unable to add contacts: ".$e);
}
}
}
?>