Completed
Push — master ( ecff25...470e9b )
by Oleksandr
12s
created

GuzzleAdapter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 13
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A sendGetRequest() 0 13 2
A __construct() 0 4 1
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Zed\Episerver\Business\Api\Adapter\Http;
9
10
use GuzzleHttp\Client;
11
use GuzzleHttp\Exception\RequestException;
12
use Psr\Http\Message\ResponseInterface;
13
use SprykerEco\Zed\Episerver\Business\Exception\ApiHttpRequestException;
14
use SprykerEco\Zed\Episerver\EpiserverConfig;
15
16
class GuzzleAdapter implements HttpAdapterInterface
17
{
18
    /**
19
     * @var \SprykerEco\Zed\Episerver\EpiserverConfig
20
     */
21
    protected $config;
22
23
    /**
24
     * @var \GuzzleHttp\Client
25
     */
26
    protected $client;
27
28
    /**
29
     * @param \SprykerEco\Zed\Episerver\EpiserverConfig $config
30
     * @param \GuzzleHttp\Client $client
31
     */
32
    public function __construct(EpiserverConfig $config, Client $client)
33
    {
34
        $this->config = $config;
35
        $this->client = $client;
36
    }
37
38
    /**
39
     * @param string $gatewayUrl
40
     *
41
     * @throws \SprykerEco\Zed\Episerver\Business\Exception\ApiHttpRequestException
42
     *
43
     * @return \Psr\Http\Message\ResponseInterface
44
     */
45
    public function sendGetRequest(string $gatewayUrl): ResponseInterface
46
    {
47
        try {
48
            $response = $this->client->get($gatewayUrl);
49
        } catch (RequestException $requestException) {
50
            throw new ApiHttpRequestException(
51
                $requestException->getMessage(),
52
                $requestException->getCode(),
53
                $requestException->getPrevious()
54
            );
55
        }
56
57
        return $response;
58
    }
59
}
60