Passed
Push — master ( debac0...101097 )
by Ghazi
02:32 queued 15s
created

UrlBuilder::getJoinMeetingURL()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
5
 *
6
 * Copyright (c) 2016-2024 BigBlueButton Inc. and by respective authors (see below).
7
 *
8
 * This program is free software; you can redistribute it and/or modify it under the
9
 * terms of the GNU Lesser General Public License as published by the Free Software
10
 * Foundation; either version 3.0 of the License, or (at your option) any later
11
 * version.
12
 *
13
 * BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
14
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public License along
18
 * with BigBlueButton; if not, see <https://www.gnu.org/licenses/>.
19
 */
20
21
namespace BigBlueButton\Util;
22
23
use BigBlueButton\Core\ApiMethod;
24
use BigBlueButton\Parameters\CreateMeetingParameters;
25
use BigBlueButton\Parameters\DeleteRecordingsParameters;
26
use BigBlueButton\Parameters\EndMeetingParameters;
27
use BigBlueButton\Parameters\GetMeetingInfoParameters;
28
use BigBlueButton\Parameters\GetRecordingsParameters;
29
use BigBlueButton\Parameters\GetRecordingTextTracksParameters;
30
use BigBlueButton\Parameters\HooksCreateParameters;
31
use BigBlueButton\Parameters\HooksDestroyParameters;
32
use BigBlueButton\Parameters\InsertDocumentParameters;
33
use BigBlueButton\Parameters\IsMeetingRunningParameters;
34
use BigBlueButton\Parameters\JoinMeetingParameters;
35
use BigBlueButton\Parameters\PublishRecordingsParameters;
36
use BigBlueButton\Parameters\PutRecordingTextTrackParameters;
37
use BigBlueButton\Parameters\UpdateRecordingsParameters;
38
39
/**
40
 * Class UrlBuilder.
41
 */
42
class UrlBuilder
43
{
44
    protected string $hashingAlgorithm;
45
46
    private string $securitySalt;
47
48
    private string $bbbServerBaseUrl;
49
50
    public function __construct(string $secret, string $serverBaseUrl, string $hashingAlgorithm)
51
    {
52
        $this->securitySalt     = $secret;
53
        $this->bbbServerBaseUrl = $serverBaseUrl;
54
        $this->hashingAlgorithm = $hashingAlgorithm;
55
    }
56
57
    /**
58
     * Sets the hashing algorithm.
59
     */
60
    public function setHashingAlgorithm(string $hashingAlgorithm): void
61
    {
62
        $this->hashingAlgorithm = $hashingAlgorithm;
63
    }
64
65
    /**
66
     * Builds an API method URL that includes the url + params + its generated checksum.
67
     */
68
    public function buildUrl(string $method = '', string $params = '', bool $append = true): string
69
    {
70
        return $this->bbbServerBaseUrl . 'api/' . $method . ($append ? '?' . $this->buildQs($method, $params) : '');
71
    }
72
73
    /**
74
     * Builds a query string for an API method URL that includes the params + its generated checksum.
75
     */
76
    public function buildQs(string $method = '', string $params = ''): string
77
    {
78
        return $params . '&checksum=' . hash($this->hashingAlgorithm, $method . $params . $this->securitySalt);
79
    }
80
81
    // URL-Generators
82
    public function getCreateMeetingUrl(CreateMeetingParameters $createMeetingParams): string
83
    {
84
        return $this->buildUrl(ApiMethod::CREATE, $createMeetingParams->getHTTPQuery());
85
    }
86
87
    public function getJoinMeetingURL(JoinMeetingParameters $joinMeetingParams): string
88
    {
89
        return $this->buildUrl(ApiMethod::JOIN, $joinMeetingParams->getHTTPQuery());
90
    }
91
92
    public function getEndMeetingURL(EndMeetingParameters $endParams): string
93
    {
94
        return $this->buildUrl(ApiMethod::END, $endParams->getHTTPQuery());
95
    }
96
97
    public function getInsertDocumentUrl(InsertDocumentParameters $insertDocumentParameters): string
98
    {
99
        return $this->buildUrl(ApiMethod::INSERT_DOCUMENT, $insertDocumentParameters->getHTTPQuery());
100
    }
101
102
    public function getIsMeetingRunningUrl(IsMeetingRunningParameters $meetingParams): string
103
    {
104
        return $this->buildUrl(ApiMethod::IS_MEETING_RUNNING, $meetingParams->getHTTPQuery());
105
    }
106
107
    public function getMeetingsUrl(): string
108
    {
109
        return $this->buildUrl(ApiMethod::GET_MEETINGS);
110
    }
111
112
    public function getMeetingInfoUrl(GetMeetingInfoParameters $meetingParams): string
113
    {
114
        return $this->buildUrl(ApiMethod::GET_MEETING_INFO, $meetingParams->getHTTPQuery());
115
    }
116
117
    public function getRecordingsUrl(GetRecordingsParameters $recordingsParams): string
118
    {
119
        return $this->buildUrl(ApiMethod::GET_RECORDINGS, $recordingsParams->getHTTPQuery());
120
    }
121
122
    public function getPublishRecordingsUrl(PublishRecordingsParameters $recordingParams): string
123
    {
124
        return $this->buildUrl(ApiMethod::PUBLISH_RECORDINGS, $recordingParams->getHTTPQuery());
125
    }
126
127
    public function getDeleteRecordingsUrl(DeleteRecordingsParameters $recordingParams): string
128
    {
129
        return $this->buildUrl(ApiMethod::DELETE_RECORDINGS, $recordingParams->getHTTPQuery());
130
    }
131
132
    public function getUpdateRecordingsUrl(UpdateRecordingsParameters $recordingParams): string
133
    {
134
        return $this->buildUrl(ApiMethod::UPDATE_RECORDINGS, $recordingParams->getHTTPQuery());
135
    }
136
137
    public function getRecordingTextTracksUrl(GetRecordingTextTracksParameters $getRecordingTextTracksParameters): string
138
    {
139
        return $this->buildUrl(ApiMethod::GET_RECORDING_TEXT_TRACKS, $getRecordingTextTracksParameters->getHTTPQuery());
140
    }
141
142
    public function getPutRecordingTextTrackUrl(PutRecordingTextTrackParameters $putRecordingTextTrackParams): string
143
    {
144
        return $this->buildUrl(ApiMethod::PUT_RECORDING_TEXT_TRACK, $putRecordingTextTrackParams->getHTTPQuery());
145
    }
146
147
    public function getHooksCreateUrl(HooksCreateParameters $hookCreateParams): string
148
    {
149
        return $this->buildUrl(ApiMethod::HOOKS_CREATE, $hookCreateParams->getHTTPQuery());
150
    }
151
152
    public function getHooksListUrl(): string
153
    {
154
        return $this->buildUrl(ApiMethod::HOOKS_LIST);
155
    }
156
157
    public function getHooksDestroyUrl(HooksDestroyParameters $hooksDestroyParams): string
158
    {
159
        return $this->buildUrl(ApiMethod::HOOKS_DESTROY, $hooksDestroyParams->getHTTPQuery());
160
    }
161
}
162