Skip to content

Commit 101097b

Browse files
authored
Merge pull request #218 from DigitalTimK/url-builder
Improve UrlBuilder (SOLID - Seperation of Concern)
2 parents debac0c + 97451d0 commit 101097b

File tree

4 files changed

+340
-39
lines changed

4 files changed

+340
-39
lines changed

src/BigBlueButton.php

Lines changed: 103 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
namespace BigBlueButton;
2222

23-
use BigBlueButton\Core\ApiMethod;
2423
use BigBlueButton\Enum\HashingAlgorithm;
2524
use BigBlueButton\Exceptions\BadResponseException;
2625
use BigBlueButton\Parameters\CreateMeetingParameters;
@@ -62,11 +61,11 @@ class BigBlueButton
6261
{
6362
protected string $bbbSecret;
6463
protected string $bbbBaseUrl;
65-
protected UrlBuilder $urlBuilder;
6664
protected string $jSessionId;
67-
6865
protected string $hashingAlgorithm;
6966

67+
protected UrlBuilder $urlBuilder;
68+
7069
/**
7170
* @var array<int, mixed>
7271
*/
@@ -102,6 +101,9 @@ public function __construct(?string $baseUrl = null, ?string $secret = null, ?ar
102101
$this->curlOpts = $opts['curl'] ?? [];
103102
}
104103

104+
/**
105+
* @deprecated Replaced by same function-name provided by UrlBuilder-class
106+
*/
105107
public function setHashingAlgorithm(string $hashingAlgorithm): void
106108
{
107109
$this->hashingAlgorithm = $hashingAlgorithm;
@@ -126,62 +128,74 @@ public function getApiVersion(): ApiVersionResponse
126128
-- insertDocument
127129
*/
128130

131+
/**
132+
* @deprecated Replaced by same function-name provided by UrlBuilder-class
133+
*/
129134
public function getCreateMeetingUrl(CreateMeetingParameters $createMeetingParams): string
130135
{
131-
return $this->urlBuilder->buildUrl(ApiMethod::CREATE, $createMeetingParams->getHTTPQuery());
136+
return $this->urlBuilder->getCreateMeetingUrl($createMeetingParams);
132137
}
133138

134139
/**
135140
* @throws BadResponseException|\RuntimeException
136141
*/
137142
public function createMeeting(CreateMeetingParameters $createMeetingParams): CreateMeetingResponse
138143
{
139-
$xml = $this->processXmlResponse($this->getCreateMeetingUrl($createMeetingParams), $createMeetingParams->getPresentationsAsXML());
144+
$xml = $this->processXmlResponse($this->urlBuilder->getCreateMeetingUrl($createMeetingParams), $createMeetingParams->getPresentationsAsXML());
140145

141146
return new CreateMeetingResponse($xml);
142147
}
143148

149+
/**
150+
* @deprecated Replaced by same function-name provided by UrlBuilder-class
151+
*/
144152
public function getJoinMeetingURL(JoinMeetingParameters $joinMeetingParams): string
145153
{
146-
return $this->urlBuilder->buildUrl(ApiMethod::JOIN, $joinMeetingParams->getHTTPQuery());
154+
return $this->urlBuilder->getJoinMeetingURL($joinMeetingParams);
147155
}
148156

149157
/**
150158
* @throws BadResponseException|\RuntimeException
151159
*/
152160
public function joinMeeting(JoinMeetingParameters $joinMeetingParams): JoinMeetingResponse
153161
{
154-
$xml = $this->processXmlResponse($this->getJoinMeetingURL($joinMeetingParams));
162+
$xml = $this->processXmlResponse($this->urlBuilder->getJoinMeetingURL($joinMeetingParams));
155163

156164
return new JoinMeetingResponse($xml);
157165
}
158166

167+
/**
168+
* @deprecated Replaced by same function-name provided by UrlBuilder-class
169+
*/
159170
public function getEndMeetingURL(EndMeetingParameters $endParams): string
160171
{
161-
return $this->urlBuilder->buildUrl(ApiMethod::END, $endParams->getHTTPQuery());
172+
return $this->urlBuilder->getEndMeetingURL($endParams);
162173
}
163174

164175
/**
165176
* @throws BadResponseException|\RuntimeException
166177
*/
167178
public function endMeeting(EndMeetingParameters $endParams): EndMeetingResponse
168179
{
169-
$xml = $this->processXmlResponse($this->getEndMeetingURL($endParams));
180+
$xml = $this->processXmlResponse($this->urlBuilder->getEndMeetingURL($endParams));
170181

171182
return new EndMeetingResponse($xml);
172183
}
173184

185+
/**
186+
* @deprecated Replaced by same function-name provided by UrlBuilder-class
187+
*/
174188
public function getInsertDocumentUrl(InsertDocumentParameters $insertDocumentParameters): string
175189
{
176-
return $this->urlBuilder->buildUrl(ApiMethod::INSERT_DOCUMENT, $insertDocumentParameters->getHTTPQuery());
190+
return $this->urlBuilder->getInsertDocumentUrl($insertDocumentParameters);
177191
}
178192

179193
/**
180194
* @throws BadResponseException|\RuntimeException
181195
*/
182196
public function insertDocument(InsertDocumentParameters $insertDocumentParams): CreateMeetingResponse
183197
{
184-
$xml = $this->processXmlResponse($this->getInsertDocumentUrl($insertDocumentParams), $insertDocumentParams->getPresentationsAsXML());
198+
$xml = $this->processXmlResponse($this->urlBuilder->getInsertDocumentUrl($insertDocumentParams), $insertDocumentParams->getPresentationsAsXML());
185199

186200
return new CreateMeetingResponse($xml);
187201
}
@@ -193,47 +207,56 @@ public function insertDocument(InsertDocumentParameters $insertDocumentParams):
193207
-- getMeetingInfo
194208
*/
195209

210+
/**
211+
* @deprecated Replaced by same function-name provided by UrlBuilder-class
212+
*/
196213
public function getIsMeetingRunningUrl(IsMeetingRunningParameters $meetingParams): string
197214
{
198-
return $this->urlBuilder->buildUrl(ApiMethod::IS_MEETING_RUNNING, $meetingParams->getHTTPQuery());
215+
return $this->urlBuilder->getIsMeetingRunningUrl($meetingParams);
199216
}
200217

201218
/**
202219
* @throws BadResponseException|\RuntimeException
203220
*/
204221
public function isMeetingRunning(IsMeetingRunningParameters $meetingParams): IsMeetingRunningResponse
205222
{
206-
$xml = $this->processXmlResponse($this->getIsMeetingRunningUrl($meetingParams));
223+
$xml = $this->processXmlResponse($this->urlBuilder->getIsMeetingRunningUrl($meetingParams));
207224

208225
return new IsMeetingRunningResponse($xml);
209226
}
210227

228+
/**
229+
* @deprecated Replaced by same function-name provided by UrlBuilder-class
230+
*/
211231
public function getMeetingsUrl(): string
212232
{
213-
return $this->urlBuilder->buildUrl(ApiMethod::GET_MEETINGS);
233+
return $this->urlBuilder->getMeetingsUrl();
214234
}
215235

216236
/**
217237
* @throws BadResponseException|\RuntimeException
218238
*/
219239
public function getMeetings(): GetMeetingsResponse
220240
{
221-
$xml = $this->processXmlResponse($this->getMeetingsUrl());
241+
$xml = $this->processXmlResponse($this->urlBuilder->getMeetingsUrl());
222242

223243
return new GetMeetingsResponse($xml);
224244
}
225245

246+
/**
247+
* @deprecated Replaced by same function-name provided by UrlBuilder-class
248+
*/
226249
public function getMeetingInfoUrl(GetMeetingInfoParameters $meetingParams): string
227250
{
228-
return $this->urlBuilder->buildUrl(ApiMethod::GET_MEETING_INFO, $meetingParams->getHTTPQuery());
251+
return $this->urlBuilder->getMeetingInfoUrl($meetingParams);
229252
}
230253

231254
/**
232255
* @throws BadResponseException|\RuntimeException
233256
*/
234257
public function getMeetingInfo(GetMeetingInfoParameters $meetingParams): GetMeetingInfoResponse
235258
{
236-
$xml = $this->processXmlResponse($this->getMeetingInfoUrl($meetingParams));
259+
$xml = $this->processXmlResponse($this->urlBuilder->getMeetingInfoUrl($meetingParams));
237260

238261
return new GetMeetingInfoResponse($xml);
239262
}
@@ -245,9 +268,12 @@ public function getMeetingInfo(GetMeetingInfoParameters $meetingParams): GetMeet
245268
-- deleteRecordings
246269
*/
247270

271+
/**
272+
* @deprecated Replaced by same function-name provided by UrlBuilder-class
273+
*/
248274
public function getRecordingsUrl(GetRecordingsParameters $recordingsParams): string
249275
{
250-
return $this->urlBuilder->buildUrl(ApiMethod::GET_RECORDINGS, $recordingsParams->getHTTPQuery());
276+
return $this->urlBuilder->getRecordingsUrl($recordingsParams);
251277
}
252278

253279
/**
@@ -257,82 +283,109 @@ public function getRecordingsUrl(GetRecordingsParameters $recordingsParams): str
257283
*/
258284
public function getRecordings($recordingParams): GetRecordingsResponse
259285
{
260-
$xml = $this->processXmlResponse($this->getRecordingsUrl($recordingParams));
286+
$xml = $this->processXmlResponse($this->urlBuilder->getRecordingsUrl($recordingParams));
261287

262288
return new GetRecordingsResponse($xml);
263289
}
264290

291+
/**
292+
* @deprecated Replaced by same function-name provided by UrlBuilder-class
293+
*/
265294
public function getPublishRecordingsUrl(PublishRecordingsParameters $recordingParams): string
266295
{
267-
return $this->urlBuilder->buildUrl(ApiMethod::PUBLISH_RECORDINGS, $recordingParams->getHTTPQuery());
296+
return $this->urlBuilder->getPublishRecordingsUrl($recordingParams);
268297
}
269298

299+
/**
300+
* @throws BadResponseException
301+
*/
270302
public function publishRecordings(PublishRecordingsParameters $recordingParams): PublishRecordingsResponse
271303
{
272-
$xml = $this->processXmlResponse($this->getPublishRecordingsUrl($recordingParams));
304+
$xml = $this->processXmlResponse($this->urlBuilder->getPublishRecordingsUrl($recordingParams));
273305

274306
return new PublishRecordingsResponse($xml);
275307
}
276308

309+
/**
310+
* @deprecated Replaced by same function-name provided by UrlBuilder-class
311+
*/
277312
public function getDeleteRecordingsUrl(DeleteRecordingsParameters $recordingParams): string
278313
{
279-
return $this->urlBuilder->buildUrl(ApiMethod::DELETE_RECORDINGS, $recordingParams->getHTTPQuery());
314+
return $this->urlBuilder->getDeleteRecordingsUrl($recordingParams);
280315
}
281316

282317
/**
283318
* @throws BadResponseException|\RuntimeException
284319
*/
285320
public function deleteRecordings(DeleteRecordingsParameters $recordingParams): DeleteRecordingsResponse
286321
{
287-
$xml = $this->processXmlResponse($this->getDeleteRecordingsUrl($recordingParams));
322+
$xml = $this->processXmlResponse($this->urlBuilder->getDeleteRecordingsUrl($recordingParams));
288323

289324
return new DeleteRecordingsResponse($xml);
290325
}
291326

327+
/**
328+
* @deprecated Replaced by same function-name provided by UrlBuilder-class
329+
*/
292330
public function getUpdateRecordingsUrl(UpdateRecordingsParameters $recordingParams): string
293331
{
294-
return $this->urlBuilder->buildUrl(ApiMethod::UPDATE_RECORDINGS, $recordingParams->getHTTPQuery());
332+
return $this->urlBuilder->getUpdateRecordingsUrl($recordingParams);
295333
}
296334

297335
/**
298336
* @throws BadResponseException|\RuntimeException
299337
*/
300338
public function updateRecordings(UpdateRecordingsParameters $recordingParams): UpdateRecordingsResponse
301339
{
302-
$xml = $this->processXmlResponse($this->getUpdateRecordingsUrl($recordingParams));
340+
$xml = $this->processXmlResponse($this->urlBuilder->getUpdateRecordingsUrl($recordingParams));
303341

304342
return new UpdateRecordingsResponse($xml);
305343
}
306344

345+
/**
346+
* @deprecated Replaced by same function-name provided by UrlBuilder-class
347+
*/
307348
public function getRecordingTextTracksUrl(GetRecordingTextTracksParameters $getRecordingTextTracksParameters): string
308349
{
309-
return $this->urlBuilder->buildUrl(ApiMethod::GET_RECORDING_TEXT_TRACKS, $getRecordingTextTracksParameters->getHTTPQuery());
350+
return $this->urlBuilder->getRecordingTextTracksUrl($getRecordingTextTracksParameters);
310351
}
311352

353+
/**
354+
* @throws BadResponseException
355+
*/
312356
public function getRecordingTextTracks(GetRecordingTextTracksParameters $getRecordingTextTracksParams): GetRecordingTextTracksResponse
313357
{
314-
$json = $this->processJsonResponse($this->getRecordingTextTracksUrl($getRecordingTextTracksParams));
358+
$json = $this->processJsonResponse($this->urlBuilder->getRecordingTextTracksUrl($getRecordingTextTracksParams));
315359

316360
return new GetRecordingTextTracksResponse($json);
317361
}
318362

363+
/**
364+
* @deprecated Replaced by same function-name provided by UrlBuilder-class
365+
*/
319366
public function getPutRecordingTextTrackUrl(PutRecordingTextTrackParameters $putRecordingTextTrackParams): string
320367
{
321-
return $this->urlBuilder->buildUrl(ApiMethod::PUT_RECORDING_TEXT_TRACK, $putRecordingTextTrackParams->getHTTPQuery());
368+
return $this->urlBuilder->getPutRecordingTextTrackUrl($putRecordingTextTrackParams);
322369
}
323370

371+
/**
372+
* @throws BadResponseException
373+
*/
324374
public function putRecordingTextTrack(PutRecordingTextTrackParameters $putRecordingTextTrackParams): PutRecordingTextTrackResponse
325375
{
326-
$json = $this->processJsonResponse($this->getPutRecordingTextTrackUrl($putRecordingTextTrackParams));
376+
$json = $this->processJsonResponse($this->urlBuilder->getPutRecordingTextTrackUrl($putRecordingTextTrackParams));
327377

328378
return new PutRecordingTextTrackResponse($json);
329379
}
330380

331381
// ____________________ WEB HOOKS METHODS ___________________
332382

383+
/**
384+
* @deprecated Replaced by same function-name provided by UrlBuilder-class
385+
*/
333386
public function getHooksCreateUrl(HooksCreateParameters $hookCreateParams): string
334387
{
335-
return $this->urlBuilder->buildUrl(ApiMethod::HOOKS_CREATE, $hookCreateParams->getHTTPQuery());
388+
return $this->urlBuilder->getHooksCreateUrl($hookCreateParams);
336389
}
337390

338391
/**
@@ -342,26 +395,35 @@ public function getHooksCreateUrl(HooksCreateParameters $hookCreateParams): stri
342395
*/
343396
public function hooksCreate($hookCreateParams): HooksCreateResponse
344397
{
345-
$xml = $this->processXmlResponse($this->getHooksCreateUrl($hookCreateParams));
398+
$xml = $this->processXmlResponse($this->urlBuilder->getHooksCreateUrl($hookCreateParams));
346399

347400
return new HooksCreateResponse($xml);
348401
}
349402

403+
/**
404+
* @deprecated Replaced by same function-name provided by UrlBuilder-class
405+
*/
350406
public function getHooksListUrl(): string
351407
{
352-
return $this->urlBuilder->buildUrl(ApiMethod::HOOKS_LIST);
408+
return $this->urlBuilder->getHooksListUrl();
353409
}
354410

411+
/**
412+
* @throws BadResponseException
413+
*/
355414
public function hooksList(): HooksListResponse
356415
{
357-
$xml = $this->processXmlResponse($this->getHooksListUrl());
416+
$xml = $this->processXmlResponse($this->urlBuilder->getHooksListUrl());
358417

359418
return new HooksListResponse($xml);
360419
}
361420

421+
/**
422+
* @deprecated Replaced by same function-name provided by UrlBuilder-class
423+
*/
362424
public function getHooksDestroyUrl(HooksDestroyParameters $hooksDestroyParams): string
363425
{
364-
return $this->urlBuilder->buildUrl(ApiMethod::HOOKS_DESTROY, $hooksDestroyParams->getHTTPQuery());
426+
return $this->urlBuilder->getHooksDestroyUrl($hooksDestroyParams);
365427
}
366428

367429
/**
@@ -371,7 +433,7 @@ public function getHooksDestroyUrl(HooksDestroyParameters $hooksDestroyParams):
371433
*/
372434
public function hooksDestroy($hooksDestroyParams): HooksDestroyResponse
373435
{
374-
$xml = $this->processXmlResponse($this->getHooksDestroyUrl($hooksDestroyParams));
436+
$xml = $this->processXmlResponse($this->urlBuilder->getHooksDestroyUrl($hooksDestroyParams));
375437

376438
return new HooksDestroyResponse($xml);
377439
}
@@ -407,6 +469,8 @@ public function setTimeOut(int $TimeOutInSeconds): self
407469
}
408470

409471
/**
472+
* @deprecated Replaced by same function-name provided by UrlBuilder-BigBlueButton
473+
*
410474
* Public accessor for buildUrl.
411475
*/
412476
public function buildUrl(string $method = '', string $params = '', bool $append = true): string
@@ -503,18 +567,18 @@ private function sendRequest(string $url, string $payload = '', string $contentT
503567
*
504568
* @throws BadResponseException|\Exception
505569
*/
506-
private function processXmlResponse(string $url, string $payload = '', string $contentType = 'application/xml'): \SimpleXMLElement
570+
private function processXmlResponse(string $url, string $payload = ''): \SimpleXMLElement
507571
{
508-
return new \SimpleXMLElement($this->sendRequest($url, $payload, $contentType));
572+
return new \SimpleXMLElement($this->sendRequest($url, $payload, 'application/xml'));
509573
}
510574

511575
/**
512576
* A private utility method used by other public methods to process json responses.
513577
*
514578
* @throws BadResponseException
515579
*/
516-
private function processJsonResponse(string $url, string $payload = '', string $contentType = 'application/json'): string
580+
private function processJsonResponse(string $url, string $payload = ''): string
517581
{
518-
return $this->sendRequest($url, $payload, $contentType);
582+
return $this->sendRequest($url, $payload, 'application/json');
519583
}
520584
}

0 commit comments

Comments
 (0)