Completed
Pull Request — master (#18)
by Jesus
02:56
created

UrlBuilder::buildQs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
/**
3
 * BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
4
 *
5
 * Copyright (c) 2016 BigBlueButton Inc. and by respective authors (see below).
6
 *
7
 * This program is free software; you can redistribute it and/or modify it under the
8
 * terms of the GNU Lesser General Public License as published by the Free Software
9
 * Foundation; either version 3.0 of the License, or (at your option) any later
10
 * version.
11
 *
12
 * BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
13
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
14
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License along
17
 * with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
18
 */
19
namespace BigBlueButton\Util;
20
21
/**
22
 * Class UrlBuilder
23
 * @package BigBlueButton\Util
24
 */
25
class UrlBuilder
26
{
27
    /**
28
     * @var string
29
     */
30
    private $securitySalt;
31
    /**
32
     * @var string
33
     */
34
    private $bbbServerBaseUrl;
35
36
    /**
37
     * UrlBuilder constructor.
38
     *
39
     * @param $salt
40
     * @param $serverBaseUrl
41
     */
42
    public function __construct($salt, $serverBaseUrl)
43
    {
44
        $this->securitySalt     = $salt;
45
        $this->bbbServerBaseUrl = $serverBaseUrl;
46
    }
47
48
    /**
49
     * Builds an API method URL that includes the url + params + its generated checksum.
50
     *
51
     * @param string $method
52
     * @param string $params
53
     * @param string $append
54
     *
55
     * @return string
56
     */
57
    public function buildUrl($method = '', $params = '', $append = true)
58
    {
59
        return $this->bbbServerBaseUrl.'api/'.$method.($append ? '?'.$this->buildQs($method, $params) : '');
60
    }
61
62
     /**
63
      * Builds a query string for an API method URL that includes the params + its generated checksum.
64
      *
65
      * @param string $method
66
      * @param string $params
67
      *
68
      * @return string
69
      */
70
     public function buildQs($method = '', $params = '')
71
     {
72
         return $params.'&checksum='.sha1($method.$params.$this->securitySalt);
73
     }
74
}
75