Completed
Push — 2.0 ( 59824a...0c16d7 )
by Peter
05:38
created

GuzzleClient::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 6
Bugs 0 Features 0
Metric Value
c 6
b 0
f 0
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 9
nc 1
nop 4
crap 1
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
8
 */
9
namespace AnimeDb\Bundle\AniDbBrowserBundle\Service\Client;
10
11
use AnimeDb\Bundle\AniDbBrowserBundle\Service\Client\Guzzle\RequestConfigurator;
12
use AnimeDb\Bundle\AniDbBrowserBundle\Util\ResponseRepair;
13
use GuzzleHttp\Client;
14
15
class GuzzleClient implements ClientInterface
16
{
17
    /**
18
     * @var Client
19
     */
20
    protected $client;
21
22
    /**
23
     * @var RequestConfigurator
24
     */
25
    protected $configurator;
26
27
    /**
28
     * @var ResponseRepair
29
     */
30
    protected $repair;
31
32
    /**
33
     * @var string
34
     */
35
    protected $url;
36
37
    /**
38
     * @param Client $client
39
     * @param RequestConfigurator $configurator
40
     * @param ResponseRepair $repair
41
     * @param string $api_prefix
42
     */
43 3
    public function __construct(
44
        Client $client,
45
        RequestConfigurator $configurator,
46
        ResponseRepair $repair,
47
        $api_prefix
48
    ) {
49 3
        $this->url = $api_prefix;
50 3
        $this->client = $client;
51 3
        $this->repair = $repair;
52 3
        $this->configurator = $configurator;
53 3
    }
54
55
    /**
56
     * @param int $timeout
57
     *
58
     * @return GuzzleClient
59
     */
60 1
    public function setTimeout($timeout)
61
    {
62 1
        $this->configurator->setTimeout($timeout);
63
64 1
        return $this;
65
    }
66
67
    /**
68
     * @param string $proxy
69
     *
70
     * @return GuzzleClient
71
     */
72 1
    public function setProxy($proxy)
73
    {
74 1
        $this->configurator->setProxy($proxy);
75
76 1
        return $this;
77
    }
78
79
    /**
80
     * @param string $request
81
     * @param array $params
82
     *
83
     * @return string
84
     */
85 1
    public function get($request, array $params = [])
86
    {
87 1
        $options = $this->configurator->withRequest($request, $params)->getOptions();
88 1
        $response = $this->client->request('GET', $this->url, $options);
89
90 1
        return $this->repair->repair(gzdecode($response->getBody())); // repair
91
    }
92
}
93