Completed
Push — master ( 919ad9...9a7348 )
by Victor Hugo
23s
created

FixerHttpClient::initEndpoints()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Deltatuts\Fixer;
4
5
use Deltatuts\Fixer\Endpoint\LatestExchangeRatesEndpoint;
6
use Deltatuts\Fixer\Endpoint\SymbolsEndpoint;
7
use Deltatuts\Fixer\Exception\MissingAPIKeyException;
8
use GuzzleHttp\Client;
9
use GuzzleHttp\RequestOptions;
10
11
/**
12
 * Class FixerHttpClient
13
 * @package Deltatuts\Fixer
14
 */
15
class FixerHttpClient extends Client
16
{
17
    const BASE_URI = "http://data.fixer.io/api";
18
19
    /**
20
     * Time to wait in seconds before interrupting the request.
21
     */
22
    const TIMEOUT = 5;
23
24
    /**
25
     * @var string
26
     */
27
    private $apiKey;
28
29
    /**
30
     * @var SymbolsEndpoint
31
     */
32
    public $symbols;
33
34
    /**
35
     * @var LatestExchangeRatesEndpoint
36
     */
37
    public $rates;
38
39
    /**
40
     * FixerHttpClient constructor.
41
     *
42
     * @param string $key
43
     * @param array $config
44
     * @throws MissingAPIKeyException
45
     */
46 27
    public function __construct(string $key, array $config = [])
47
    {
48 27
        if (empty($key)) {
49 3
            throw new MissingAPIKeyException();
50
        }
51
52 24
        $this->apiKey = $key;
53
        $baseConfig = [
54 24
            'base_uri' => self::BASE_URI,
55 24
            RequestOptions::TIMEOUT => self::TIMEOUT
56
        ];
57 24
        parent::__construct(array_merge($baseConfig, $config));
58 24
        $this->initEndpoints();
59 24
    }
60
61
    /**
62
     * @return string
63
     */
64 15
    public function getApiKey(): string
65
    {
66 15
        return $this->apiKey;
67
    }
68
69
    /**
70
     * Initializes all the supported endpoints.
71
     */
72 24
    private function initEndpoints()
73
    {
74 24
        $this->symbols = new SymbolsEndpoint($this);
75 24
        $this->rates = new LatestExchangeRatesEndpoint($this);
76 24
    }
77
}
78