1 | <?php namespace Arcanedev\Currencies\Converters; |
||
12 | class OpenExchangeRatesConverter extends AbstractConverter |
||
13 | { |
||
14 | /* ------------------------------------------------------------------------------------------------ |
||
15 | | Properties |
||
16 | | ------------------------------------------------------------------------------------------------ |
||
17 | */ |
||
18 | /** |
||
19 | * The base URL. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $baseUrl = 'http://openexchangerates.org/api'; |
||
24 | |||
25 | /** |
||
26 | * The API ID. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $apiId; |
||
31 | |||
32 | /** |
||
33 | * @var bool |
||
34 | */ |
||
35 | protected $proPlan; |
||
36 | |||
37 | /* ------------------------------------------------------------------------------------------------ |
||
38 | | Getters & Setters |
||
39 | | ------------------------------------------------------------------------------------------------ |
||
40 | */ |
||
41 | /** |
||
42 | * Set the configs. |
||
43 | * |
||
44 | * @param array $configs |
||
45 | * |
||
46 | * @return mixed |
||
47 | */ |
||
48 | 24 | protected function setProviderConfigs(array $configs) |
|
53 | |||
54 | /** |
||
55 | * Get the API ID. |
||
56 | * |
||
57 | * @return string |
||
58 | * |
||
59 | * @throws \Exception |
||
60 | */ |
||
61 | 12 | private function getAppId() |
|
62 | { |
||
63 | 12 | if ( ! $this->apiId) { |
|
64 | throw new \Exception('OpenExchangeRates.org requires an app key.'); |
||
65 | } |
||
66 | |||
67 | 12 | return $this->apiId; |
|
68 | } |
||
69 | |||
70 | 12 | private function getFromCurrency($from) |
|
78 | |||
79 | 12 | private function getToCurrencies($to) |
|
90 | |||
91 | /* ------------------------------------------------------------------------------------------------ |
||
92 | | Main Functions |
||
93 | | ------------------------------------------------------------------------------------------------ |
||
94 | */ |
||
95 | /** |
||
96 | * Get currencies rates. |
||
97 | * |
||
98 | * @param string|null $from |
||
99 | * @param array|string|null $to |
||
100 | * |
||
101 | * @return RateCollection |
||
102 | */ |
||
103 | 12 | public function rates($from = null, $to = null) |
|
117 | |||
118 | /** |
||
119 | * Make an API request. |
||
120 | * |
||
121 | * @param string $from |
||
122 | * @param array $to |
||
123 | * |
||
124 | * @return RateCollection |
||
125 | * |
||
126 | * @throws \Exception |
||
127 | */ |
||
128 | 12 | protected function request($from, array $to) |
|
142 | |||
143 | /** |
||
144 | * Prepare rates collection. |
||
145 | * |
||
146 | * @param string $from |
||
147 | * @param array $rates |
||
148 | * |
||
149 | * @return RateCollection |
||
150 | */ |
||
151 | 12 | protected function prepareRates($from, array $rates) |
|
155 | } |
||
156 |