|
1
|
|
|
<?php
|
|
2
|
|
|
/**
|
|
3
|
|
|
* UnionCloud Wrapper Class
|
|
4
|
|
|
*/
|
|
5
|
|
|
|
|
6
|
|
|
namespace Twigger\UnionCloud\API;
|
|
7
|
|
|
|
|
8
|
|
|
use Twigger\UnionCloud\API\Auth\Authentication;
|
|
9
|
|
|
use Twigger\UnionCloud\API\Auth\IAuthenticator;
|
|
10
|
|
|
use Twigger\UnionCloud\API\Exception\Authentication\AuthenticatorNotFound;
|
|
11
|
|
|
use Twigger\UnionCloud\API\Exception\Authentication\BaseUnionCloudAuthenticationException;
|
|
12
|
|
|
use Twigger\UnionCloud\API\Request;
|
|
13
|
|
|
|
|
14
|
|
|
/**
|
|
15
|
|
|
* Class UnionCloud
|
|
16
|
|
|
*
|
|
17
|
|
|
* Choose your resource from here!
|
|
18
|
|
|
*
|
|
19
|
|
|
* @package Twigger\UnionCloud\API\Core
|
|
20
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 GNU Public License v3
|
|
21
|
|
|
* @author Toby Twigger <[email protected]>
|
|
22
|
|
|
*/
|
|
23
|
|
|
|
|
24
|
|
|
class UnionCloud
|
|
25
|
|
|
{
|
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/*
|
|
29
|
|
|
|--------------------------------------------------------------------------
|
|
30
|
|
|
| Class Holders
|
|
31
|
|
|
|--------------------------------------------------------------------------
|
|
32
|
|
|
|
|
|
33
|
|
|
| Holders for the authenticator and configuration
|
|
34
|
|
|
|
|
|
35
|
|
|
*/
|
|
36
|
|
|
|
|
37
|
|
|
/**
|
|
38
|
|
|
* Holds the Authentication wrapper, a wrapper for the authenticator
|
|
39
|
|
|
*
|
|
40
|
|
|
* @var Authentication
|
|
41
|
|
|
*/
|
|
42
|
|
|
protected $authentication = null;
|
|
43
|
|
|
|
|
44
|
|
|
/**
|
|
45
|
|
|
* Holds configuration variables
|
|
46
|
|
|
* - Base URL
|
|
47
|
|
|
* - Debug
|
|
48
|
|
|
* @var Configuration
|
|
49
|
|
|
*/
|
|
50
|
|
|
protected $configuration;
|
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
/**
|
|
54
|
|
|
* UnionCloud constructor.
|
|
55
|
|
|
*
|
|
56
|
|
|
* Creates an Authenticator and a blank Configuration
|
|
57
|
|
|
*
|
|
58
|
|
|
* @param null|array $authParams Associative array of the Authentication Parameters
|
|
59
|
|
|
* @param null|string $authenticator AuthenticatorClass::class
|
|
60
|
|
|
*
|
|
61
|
|
|
* @throws AuthenticatorNotFound
|
|
62
|
|
|
* @throws Exception\Authentication\AuthenticationParameterMissing
|
|
63
|
|
|
*/
|
|
64
|
|
|
public function __construct($authParams = null, $authenticator = null)
|
|
65
|
|
|
{
|
|
66
|
|
|
$this->authentication = new Authentication($authParams, $authenticator);
|
|
67
|
|
|
$this->configuration = new Configuration();
|
|
68
|
|
|
}
|
|
69
|
|
|
|
|
70
|
|
|
/**
|
|
71
|
|
|
* Manually set the authenticator
|
|
72
|
|
|
*
|
|
73
|
|
|
* @param IAuthenticator $authenticator
|
|
74
|
|
|
*
|
|
75
|
|
|
* @throws BaseUnionCloudAuthenticationException
|
|
76
|
|
|
*/
|
|
77
|
|
|
public function setAuthenticator($authenticator)
|
|
78
|
|
|
{
|
|
79
|
|
|
$this->authentication->setAuthenticator($authenticator);
|
|
80
|
|
|
}
|
|
81
|
|
|
|
|
82
|
|
|
/**
|
|
83
|
|
|
* Check UnionCloud is ready for the request
|
|
84
|
|
|
*
|
|
85
|
|
|
* @throws AuthenticatorNotFound
|
|
86
|
|
|
*
|
|
87
|
|
|
* @return void
|
|
88
|
|
|
*/
|
|
89
|
|
|
private function checkReadyForRequest()
|
|
90
|
|
|
{
|
|
91
|
|
|
if (!$this->authentication->hasAuthentication())
|
|
92
|
|
|
{
|
|
93
|
|
|
throw new AuthenticatorNotFound();
|
|
94
|
|
|
}
|
|
95
|
|
|
return;
|
|
96
|
|
|
}
|
|
97
|
|
|
|
|
98
|
|
|
/**
|
|
99
|
|
|
* Set the Base URL in the configuration class
|
|
100
|
|
|
*
|
|
101
|
|
|
* @param string $baseURL
|
|
102
|
|
|
*/
|
|
103
|
|
|
public function setBaseURL($baseURL)
|
|
104
|
|
|
{
|
|
105
|
|
|
$this->configuration->setBaseUrl($baseURL);
|
|
106
|
|
|
}
|
|
107
|
|
|
|
|
108
|
|
|
/**
|
|
109
|
|
|
* Set the debug status of the API call.
|
|
110
|
|
|
*
|
|
111
|
|
|
* By calling debug(), you'll see a lot more details
|
|
112
|
|
|
* about the API call.
|
|
113
|
|
|
*
|
|
114
|
|
|
* @param bool $debug Defaults to true
|
|
115
|
|
|
*/
|
|
116
|
|
|
public function debug($debug = true)
|
|
117
|
|
|
{
|
|
118
|
|
|
$this->configuration->setDebug($debug);
|
|
119
|
|
|
}
|
|
120
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
/*
|
|
123
|
|
|
|--------------------------------------------------------------------------
|
|
124
|
|
|
| API Request Classes
|
|
125
|
|
|
|--------------------------------------------------------------------------
|
|
126
|
|
|
|
|
|
127
|
|
|
| A set of functions which return request classes, allowing access to
|
|
128
|
|
|
| the methods of each resource
|
|
129
|
|
|
|
|
|
130
|
|
|
*/
|
|
131
|
|
|
|
|
132
|
|
|
/**
|
|
133
|
|
|
* Return an election category resource request.
|
|
134
|
|
|
*
|
|
135
|
|
|
* @return Request\ElectionCategoryRequest
|
|
136
|
|
|
*
|
|
137
|
|
|
* @throws AuthenticatorNotFound
|
|
138
|
|
|
*/
|
|
139
|
|
|
public function electionCategories()
|
|
140
|
|
|
{
|
|
141
|
|
|
$this->checkReadyForRequest();
|
|
142
|
|
|
return new Request\ElectionCategoryRequest($this->authentication, $this->configuration);
|
|
143
|
|
|
}
|
|
144
|
|
|
|
|
145
|
|
|
/**
|
|
146
|
|
|
* Return a Election Position resource request.
|
|
147
|
|
|
*
|
|
148
|
|
|
* @return Request\ElectionPositionRequest
|
|
149
|
|
|
*
|
|
150
|
|
|
* @throws AuthenticatorNotFound
|
|
151
|
|
|
*/
|
|
152
|
|
|
public function electionPositions()
|
|
153
|
|
|
{
|
|
154
|
|
|
$this->checkReadyForRequest();
|
|
155
|
|
|
return new Request\ElectionPositionRequest($this->authentication, $this->configuration);
|
|
156
|
|
|
}
|
|
157
|
|
|
|
|
158
|
|
|
/**
|
|
159
|
|
|
* Return a Election resource request.
|
|
160
|
|
|
*
|
|
161
|
|
|
* @return Request\ElectionRequest
|
|
162
|
|
|
*
|
|
163
|
|
|
* @throws AuthenticatorNotFound
|
|
164
|
|
|
*/
|
|
165
|
|
|
public function elections()
|
|
166
|
|
|
{
|
|
167
|
|
|
$this->checkReadyForRequest();
|
|
168
|
|
|
return new Request\ElectionRequest($this->authentication, $this->configuration);
|
|
169
|
|
|
}
|
|
170
|
|
|
|
|
171
|
|
|
/**
|
|
172
|
|
|
* Return a election standing resource request.
|
|
173
|
|
|
*
|
|
174
|
|
|
* @return Request\ElectionStandingRequest
|
|
175
|
|
|
*
|
|
176
|
|
|
* @throws AuthenticatorNotFound
|
|
177
|
|
|
*/
|
|
178
|
|
|
public function electionStandings()
|
|
179
|
|
|
{
|
|
180
|
|
|
$this->checkReadyForRequest();
|
|
181
|
|
|
return new Request\ElectionStandingRequest($this->authentication, $this->configuration);
|
|
182
|
|
|
}
|
|
183
|
|
|
|
|
184
|
|
|
/**
|
|
185
|
|
|
* Return a election voter demographic resource request.
|
|
186
|
|
|
*
|
|
187
|
|
|
* @return Request\ElectionVoterDemographicRequest
|
|
188
|
|
|
*
|
|
189
|
|
|
* @throws AuthenticatorNotFound
|
|
190
|
|
|
*/
|
|
191
|
|
|
public function electionVoterDemographics()
|
|
192
|
|
|
{
|
|
193
|
|
|
$this->checkReadyForRequest();
|
|
194
|
|
|
return new Request\ElectionVoterDemographicRequest($this->authentication, $this->configuration);
|
|
195
|
|
|
}
|
|
196
|
|
|
|
|
197
|
|
|
/**
|
|
198
|
|
|
* Return a election vote resource request.
|
|
199
|
|
|
*
|
|
200
|
|
|
* @return Request\ElectionVoteRequest
|
|
201
|
|
|
*
|
|
202
|
|
|
* @throws AuthenticatorNotFound
|
|
203
|
|
|
*/
|
|
204
|
|
|
public function electionVotes()
|
|
205
|
|
|
{
|
|
206
|
|
|
$this->checkReadyForRequest();
|
|
207
|
|
|
return new Request\ElectionVoteRequest($this->authentication, $this->configuration);
|
|
208
|
|
|
}
|
|
209
|
|
|
|
|
210
|
|
|
/**
|
|
211
|
|
|
* Return a election voter resource request.
|
|
212
|
|
|
*
|
|
213
|
|
|
* @return Request\ElectionVoterRequest
|
|
214
|
|
|
*
|
|
215
|
|
|
* @throws AuthenticatorNotFound
|
|
216
|
|
|
*/
|
|
217
|
|
|
public function electionVoters()
|
|
218
|
|
|
{
|
|
219
|
|
|
$this->checkReadyForRequest();
|
|
220
|
|
|
return new Request\ElectionVoterRequest($this->authentication, $this->configuration);
|
|
221
|
|
|
}
|
|
222
|
|
|
|
|
223
|
|
|
/**
|
|
224
|
|
|
* Return a event Attendee resource request.
|
|
225
|
|
|
*
|
|
226
|
|
|
* @return Request\EventAttendeeRequest
|
|
227
|
|
|
*
|
|
228
|
|
|
* @throws AuthenticatorNotFound
|
|
229
|
|
|
*/
|
|
230
|
|
|
public function eventAttendees()
|
|
231
|
|
|
{
|
|
232
|
|
|
$this->checkReadyForRequest();
|
|
233
|
|
|
return new Request\EventAttendeeRequest($this->authentication, $this->configuration);
|
|
234
|
|
|
}
|
|
235
|
|
|
|
|
236
|
|
|
/**
|
|
237
|
|
|
* Return a event question resource request.
|
|
238
|
|
|
*
|
|
239
|
|
|
* @return Request\EventQuestionRequest
|
|
240
|
|
|
*
|
|
241
|
|
|
* @throws AuthenticatorNotFound
|
|
242
|
|
|
*/
|
|
243
|
|
|
public function eventQuestions()
|
|
244
|
|
|
{
|
|
245
|
|
|
$this->checkReadyForRequest();
|
|
246
|
|
|
return new Request\EventQuestionRequest($this->authentication, $this->configuration);
|
|
247
|
|
|
}
|
|
248
|
|
|
|
|
249
|
|
|
/**
|
|
250
|
|
|
* Return a event resource request.
|
|
251
|
|
|
*
|
|
252
|
|
|
* @return Request\EventRequest
|
|
253
|
|
|
*
|
|
254
|
|
|
* @throws AuthenticatorNotFound
|
|
255
|
|
|
*/
|
|
256
|
|
|
public function events()
|
|
257
|
|
|
{
|
|
258
|
|
|
$this->checkReadyForRequest();
|
|
259
|
|
|
return new Request\EventRequest($this->authentication, $this->configuration);
|
|
260
|
|
|
}
|
|
261
|
|
|
/**
|
|
262
|
|
|
* Return a event ticket resource request.
|
|
263
|
|
|
*
|
|
264
|
|
|
* @return Request\EventTicketRequest
|
|
265
|
|
|
*
|
|
266
|
|
|
* @throws AuthenticatorNotFound
|
|
267
|
|
|
*/
|
|
268
|
|
|
public function eventTickets()
|
|
269
|
|
|
{
|
|
270
|
|
|
$this->checkReadyForRequest();
|
|
271
|
|
|
return new Request\EventTicketRequest($this->authentication, $this->configuration);
|
|
272
|
|
|
}
|
|
273
|
|
|
|
|
274
|
|
|
/**
|
|
275
|
|
|
* Return a event ticket type resource request.
|
|
276
|
|
|
*
|
|
277
|
|
|
* @return Request\EventTicketTypeRequest
|
|
278
|
|
|
*
|
|
279
|
|
|
* @throws AuthenticatorNotFound
|
|
280
|
|
|
*/
|
|
281
|
|
|
public function eventTicketTypes()
|
|
282
|
|
|
{
|
|
283
|
|
|
$this->checkReadyForRequest();
|
|
284
|
|
|
return new Request\EventTicketTypeRequest($this->authentication, $this->configuration);
|
|
285
|
|
|
}
|
|
286
|
|
|
|
|
287
|
|
|
/**
|
|
288
|
|
|
* Return a event type resource request.
|
|
289
|
|
|
*
|
|
290
|
|
|
* @return Request\EventTypeRequest
|
|
291
|
|
|
*
|
|
292
|
|
|
* @throws AuthenticatorNotFound
|
|
293
|
|
|
*/
|
|
294
|
|
|
public function eventTypes()
|
|
295
|
|
|
{
|
|
296
|
|
|
$this->checkReadyForRequest();
|
|
297
|
|
|
return new Request\EventTypeRequest($this->authentication, $this->configuration);
|
|
298
|
|
|
}
|
|
299
|
|
|
|
|
300
|
|
|
/**
|
|
301
|
|
|
* Return a group membership resource request.
|
|
302
|
|
|
*
|
|
303
|
|
|
* @return Request\GroupMembershipRequest
|
|
304
|
|
|
*
|
|
305
|
|
|
* @throws AuthenticatorNotFound
|
|
306
|
|
|
*/
|
|
307
|
|
|
public function groupMemberships()
|
|
308
|
|
|
{
|
|
309
|
|
|
$this->checkReadyForRequest();
|
|
310
|
|
|
return new Request\GroupMembershipRequest($this->authentication, $this->configuration);
|
|
311
|
|
|
}
|
|
312
|
|
|
|
|
313
|
|
|
/**
|
|
314
|
|
|
* Return a group resource request.
|
|
315
|
|
|
*
|
|
316
|
|
|
* @return Request\GroupRequest
|
|
317
|
|
|
*
|
|
318
|
|
|
* @throws AuthenticatorNotFound
|
|
319
|
|
|
*/
|
|
320
|
|
|
public function groups()
|
|
321
|
|
|
{
|
|
322
|
|
|
$this->checkReadyForRequest();
|
|
323
|
|
|
return new Request\GroupRequest($this->authentication, $this->configuration);
|
|
324
|
|
|
}
|
|
325
|
|
|
|
|
326
|
|
|
|
|
327
|
|
|
/**
|
|
328
|
|
|
* Return a programme resource request.
|
|
329
|
|
|
*
|
|
330
|
|
|
* @return Request\ProgrammeRequest
|
|
331
|
|
|
*
|
|
332
|
|
|
* @throws AuthenticatorNotFound
|
|
333
|
|
|
*/
|
|
334
|
|
|
public function programmes()
|
|
335
|
|
|
{
|
|
336
|
|
|
$this->checkReadyForRequest();
|
|
337
|
|
|
return new Request\ProgrammeRequest($this->authentication, $this->configuration);
|
|
338
|
|
|
}
|
|
339
|
|
|
|
|
340
|
|
|
/**
|
|
341
|
|
|
* Return a UserGroup Folder resource request.
|
|
342
|
|
|
*
|
|
343
|
|
|
* @return Request\UserGroupFolderRequest
|
|
344
|
|
|
*
|
|
345
|
|
|
* @throws AuthenticatorNotFound
|
|
346
|
|
|
*/
|
|
347
|
|
|
public function userGroupFolders()
|
|
348
|
|
|
{
|
|
349
|
|
|
$this->checkReadyForRequest();
|
|
350
|
|
|
return new Request\UserGroupFolderRequest($this->authentication, $this->configuration);
|
|
351
|
|
|
}
|
|
352
|
|
|
|
|
353
|
|
|
/**
|
|
354
|
|
|
* Return a UserGroup Membership resource request.
|
|
355
|
|
|
*
|
|
356
|
|
|
* @return Request\UserGroupMembershipRequest
|
|
357
|
|
|
*
|
|
358
|
|
|
* @throws AuthenticatorNotFound
|
|
359
|
|
|
*/
|
|
360
|
|
|
public function userGroupMemberships()
|
|
361
|
|
|
{
|
|
362
|
|
|
$this->checkReadyForRequest();
|
|
363
|
|
|
return new Request\UserGroupMembershipRequest($this->authentication, $this->configuration);
|
|
364
|
|
|
}
|
|
365
|
|
|
|
|
366
|
|
|
/**
|
|
367
|
|
|
* Return a usergroup resource request.
|
|
368
|
|
|
*
|
|
369
|
|
|
* @return Request\UserGroupRequest
|
|
370
|
|
|
*
|
|
371
|
|
|
* @throws AuthenticatorNotFound
|
|
372
|
|
|
*/
|
|
373
|
|
|
public function userGroups()
|
|
374
|
|
|
{
|
|
375
|
|
|
$this->checkReadyForRequest();
|
|
376
|
|
|
return new Request\UserGroupRequest($this->authentication, $this->configuration);
|
|
377
|
|
|
}
|
|
378
|
|
|
|
|
379
|
|
|
/**
|
|
380
|
|
|
* Return a user resource request.
|
|
381
|
|
|
*
|
|
382
|
|
|
* @return Request\UserRequest
|
|
383
|
|
|
*
|
|
384
|
|
|
* @throws AuthenticatorNotFound
|
|
385
|
|
|
*/
|
|
386
|
|
|
public function users()
|
|
387
|
|
|
{
|
|
388
|
|
|
$this->checkReadyForRequest();
|
|
389
|
|
|
return new Request\UserRequest($this->authentication, $this->configuration);
|
|
390
|
|
|
}
|
|
391
|
|
|
|
|
392
|
|
|
} |