-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventbrite.api.inc
344 lines (288 loc) · 11.2 KB
/
eventbrite.api.inc
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<?php
// $Id$
/**
* @file
* Provides a function for each action in the Eventbrite API.
*/
module_load_include('inc', 'eventbrite', 'eventbrite.common');
/*
* This function fetches the user's list of events from Eventbrite
*/
function _eventbrite_api_get_events() {
// Build a new request object
$request = _eventbrite_common_new_request('user_list_events', 'get');
if ($result = _eventbrite_common_process_request($request)) {
$xml_object = $result->object;
$events = array();
foreach ($xml_object as $key => $xml_event) {
if ($key == 'event' && $event = _eventbrite_api_populate_event($xml_event)) {
$events[$event->id] = $event;
}
}
return $events;
}
}
/*
* This function fetches the user's list of venues from Eventbrite
*/
function _eventbrite_api_get_venues() {
// Pull in venue handling functions
module_load_include('inc', 'eventbrite', 'eventbrite.venue');
// Build a new request object
$request = _eventbrite_common_new_request('user_list_venues', 'get');
if ($result = _eventbrite_common_process_request($request)) {
$xml_object = $result->object;
$venues = array();
// print_r($result);exit(5);
foreach ($xml_object as $key => $xml_event) {
if ($key == 'venue' && $venue = _eventbrite_api_populate_venue($xml_event)) {
$venues[$venue->venue_id] = $venue;
// If $result->updated then these venues should be saved to the DB
// TODO: Look at $result->prev_cache to see if each specific venue has changed before resaving
if ($result->updated) {
$venue->user_key = $result->user_key;
$venue->module = $result->module;
eventbrite_venue_save($venue);
}
}
}
return $venues;
}
}
/*
* This function fetches one user by user key
*/
function _eventbrite_api_get_user($user_key = '', $key_type = '') {
// Build a new request object
$request = _eventbrite_common_new_request('user_get', 'get');
switch ($key_type) {
case 'email':
$request->params['email'] = $user_key;
break;
case 'user_id':
$request->params['user_id'] = $user_key;
break;
case 'user_key':
$request->user_key = $user_key;
break;
}
if ($user_key) {
$request->$key_type = $user_key;
}
if ($result = _eventbrite_common_process_request($request)) {
$xml_object = $result->object;
if ($eb_user = _eventbrite_api_populate_user($xml_object)) {
return $eb_user;
}
}
}
/*
* This function fetches one events by Id
*/
function _eventbrite_api_get_event($event_id) {
// Build a new request object
$request = _eventbrite_common_new_request('event_get', 'get');
$request->params['id'] = $event_id;
if ($result = _eventbrite_common_process_request($request)) {
$xml_object = $result->object;
$event = _eventbrite_api_populate_event($xml_object);
return $event;
}
}
function _eventbrite_api_populate_event($event_data) {
$event = new stdClass();
$event->id = (integer)$event_data->id;
$event->title = (string)$event_data->title;
$event->description = (string)$event_data->description;
$event->start_date = (string)$event_data->start_date;
$event->end_date = (string)$event_data->end_date;
$event->timezone = (string)$event_data->timezone;
$event_venue = $event_data->venue;
if (isset($event_venue->id)) {
$event->venue_id = (integer)$event_venue->id;
}
return $event;
}
function _eventbrite_api_populate_user($user_data) {
$eb_user = new stdClass();
$eb_user->user_id = (integer)$user_data->user_id;
$eb_user->user_key = (string)$user_data->user_key;
$eb_user->email = (string)$user_data->email;
if ($subusers = (array)$user_data->subusers) {
$eb_user->subusers = array();
foreach ($subusers['subuser'] as $subuser) {
$eb_subuser = new stdClass();
$eb_subuser->user_id = (integer)$subuser->id;
$eb_subuser->email = (string)$subuser->email;
$eb_user->subusers[] = $eb_subuser;
}
}
return $eb_user;
}
function _eventbrite_api_populate_venue($venue_data) {
$venue = new stdClass();
$venue->venue_id = (integer)$venue_data->id;
$venue->name = (string)$venue_data->name;
$venue->address = (string)$venue_data->address;
$venue->city = (string)$venue_data->city;
$venue->region = (string)$venue_data->region;
$venue->country = (string)$venue_data->country;
$venue->country_code = (string)$venue_data->country_code;
$venue->longitude = (string)$venue_data->longitude;
$venue->latitude = (string)$venue_data->latitude;
return $venue;
}
function _eventbrite_api_event_new($event) {
$request = _eventbrite_common_new_request('event_new', 'save');
// Add event data to request
$request->params['title'] = $event->title;
$request->params['description'] = $event->description;
$request->params['status'] = $event->status;
$request->params['start_date'] = $event->start_date;
$request->params['end_date'] = $event->end_date;
$request->params['timezone'] = $event->timezone;
// Result will only return if no error
if ($result = _eventbrite_common_process_request($request)) {
// Populate the event coming back and return it
$xml_object = $result->object;
if ($event_id = (integer)$xml_object->id) {
// Record in watchdog
$message = (string)$xml_object->message;
watchdog('eventbrite', "Message: %message\nEventbrite Event ID: %id", array('%message' => $message, '%id' => $event_id));
// Expire the cache of event listing
_eventbrite_common_cache_expire('user_list_events');
return $event_id;
}
}
}
function _eventbrite_api_user_new($user) {
$request = _eventbrite_common_new_request('user_new', 'save');
// Add event data to request
$request->params['email'] = $user->email;
$request->params['passwd'] = $user->passwd;
// Result will only return if no error
if ($result = _eventbrite_common_process_request($request)) {
// Populate the event coming back and return it
$xml_object = $result->object;
if ($user_id = (integer)$xml_object->id) {
$eb_user = new stdClass();
$eb_user->id = $user_id;
$eb_user->user_key = (string)$xml_object->user_key;
// Record in watchdog
$message = (string)$xml_object->message;
watchdog(
'eventbrite',
"Message: %message\nEventbrite Subuser ID: %id\nUser key: %user_key",
array('%message' => $message, '%id' => $eb_user->id, '%user_key' => $eb_uesr->user_key)
);
return $eb_user;
}
}
}
function _eventbrite_api_event_update($event) {
$request = _eventbrite_common_new_request('event_update', 'save');
// Add event data to request
$request->params['event_id'] = $event->event_id;
$request->params['title'] = $event->title;
$request->params['description'] = $event->description;
$request->params['status'] = $event->status;
$request->params['start_date'] = $event->start_date;
$request->params['end_date'] = $event->end_date;
$request->params['timezone'] = $event->timezone;
$request->params['venue_id'] = $event->venue_id;
// XML data will only come back if no error
if ($result = _eventbrite_common_process_request($request)) {
// Populate the event coming back and return it
$xml_object = $result->object;
if ($event_id = (integer)$xml_object->id) {
// Record in watchdog
$message = (string)$xml_object->message;
watchdog('eventbrite', "Message: %message\nEventbrite Event ID: %id", array('%message' => $message, '%id' => $event_id));
// Expire the cache of event listing
_eventbrite_common_cache_expire('event_get', $event_id);
_eventbrite_common_cache_expire('user_list_events');
return $event_id;
}
}
}
function _eventbrite_api_ticket_new($ticket) {
$request = _eventbrite_common_new_request('ticket_new', 'save');
// Add ticket data to request
$request->params['event_id'] = $ticket->event_id;
$request->params['name'] = $ticket->name;
$request->params['quantity'] = $ticket->quantity;
$request->params['price'] = $ticket->price;
if (isset($request->params['description'])) {
$request->params['description'] = $ticket->description;
}
if (isset($request->params['is_donation'])) {
$request->params['is_donation'] = $ticket->is_donation;
}
// Result will only return if no error
if ($result = _eventbrite_common_process_request($request)) {
// Populate the event coming back and return it
$xml_object = $result->object;
// Record in watchdog
$message = (string)$xml_object->message;
$ticket_id = (integer)$xml_object->id;
watchdog('eventbrite', "Message: %message\nEventbrite Ticket ID: %id", array('%message' => $message, '%id' => $ticket_id));
return $ticket_id;
}
}
function _eventbrite_api_ticket_update($ticket) {
$request = _eventbrite_common_new_request('ticket_update', 'save');
// Add ticket data to request
$request->params['id'] = $ticket->id;
$request->params['name'] = $ticket->name;
$request->params['quantity'] = $ticket->quantity;
$request->params['price'] = $ticket->price;
if (isset($request->params['description'])) {
$request->params['description'] = $ticket->description;
}
if (isset($request->params['is_donation'])) {
$request->params['is_donation'] = $ticket->is_donation;
}
// XML data will only come back if no error
if ($result = _eventbrite_common_process_request($request)) {
// Populate the event coming back and return it
$xml_object = $result->object;
// Record in watchdog
$message = (string)$xml_data->message;
$ticket_id = (integer)$xml_object->id;
watchdog('eventbrite', "Message: %message\nEventbrite Ticket ID: %id", array('%message' => $message, '%id' => $ticket_id));
return $ticket_id;
}
}
function _eventbrite_api_payment_update($payment) {
$request = _eventbrite_common_new_request('payment_update', 'save');
// Add payment data to request
$request->params['event_id'] = $payment->event_id;
$request->params['accept_paypal'] = $payment->accept_paypal;
$request->params['paypal_email'] = $payment->paypal_email;
$request->params['accept_google'] = $payment->accept_google;
$request->params['google_merchant_id'] = $payment->google_merchant_id;
$request->params['google_merchant_key'] = $payment->google_merchant_key;
$request->params['accept_check'] = $payment->accept_check;
$request->params['instructions_check'] = $payment->instructions_check;
$request->params['accept_cash'] = $payment->accept_cash;
$request->params['instructions_cash'] = $payment->instructions_cash;
$request->params['accept_invoice'] = $payment->accept_invoice;
$request->params['instructions_invoice'] = $payment->instructions_invoice;
// XML data will only come back if no error
if ($result = _eventbrite_common_process_request($request)) {
// Populate the event coming back and return it
$xml_object = $result->object;
// Record in watchdog
$message = (string)$xml_object->message;
$event_id = (integer)$xml_object->id;
$method = (string)$xml_object->method;
watchdog(
'eventbrite',
"Message: %message\nEventbrite Payment %method for event %id",
array('%message' => $message, '%method' => $method , '%id' => $event_id)
);
// return $method;
// TODO: Returning message here rather than method since Eventbrite API does not return method
return $message;
}
}