PublicApiAccessAuth::setOptions()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is a part of nekland youtube api package
5
 *
6
 * (c) Nekland <[email protected]>
7
 *
8
 * For the full license, take a look to the LICENSE file
9
 * on the root directory of this project
10
 */
11
12
namespace Nekland\YoutubeApi\Http\Auth;
13
14
15
use Nekland\BaseApi\Http\Auth\AuthInterface;
16
use Nekland\YoutubeApi\Exception\MissingOptionException;
17
18
class PublicApiAccessAuth implements AuthInterface
19
{
20
    /**
21
     * @var array
22
     */
23
    private $options;
24
25
    /**
26
     * @param array $options
27
     * @return self
28
     * @throws \Nekland\YoutubeApi\Exception\MissingOptionException
29
     */
30
    public function setOptions(array $options)
31
    {
32
        if (empty($options['key'])) {
33
            throw new MissingOptionException(
34
                sprintf('You have to define the "key" option in order to make %s auth work.', get_class($this))
35
            );
36
        }
37
38
        $this->options = $options;
39
    }
40
41
    /**
42
     * @param \Guzzle\Http\Message\Request $request
43
     */
44
    public function auth(\Guzzle\Http\Message\Request $request)
45
    {
46
        $url = (string) $request->getUrl();
47
48
        $url .= (false === strpos($url, '?') ? '?' : '&');
49
        $url .= 'key=' . $this->options['key'];
50
51
        $request->setUrl($url);
52
    }
53
}
54