1 | <?php |
||
20 | class Currency extends Model |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * Yahoo API endpoint |
||
25 | */ |
||
26 | const API_ENDPOINT = 'https://query.yahooapis.com/v1/public/yql'; |
||
27 | |||
28 | /** |
||
29 | * Curl helper class instance |
||
30 | * @var \gplcart\core\helpers\Curl $curl |
||
31 | */ |
||
32 | protected $curl; |
||
33 | |||
34 | /** |
||
35 | * Currency model class instance |
||
36 | * @var \gplcart\core\models\Currency $currency |
||
37 | */ |
||
38 | protected $currency; |
||
39 | |||
40 | /** |
||
41 | * Logger class instance |
||
42 | * @var \gplcart\core\Logger $logger |
||
43 | */ |
||
44 | protected $logger; |
||
45 | |||
46 | /** |
||
47 | * The module settings |
||
48 | * @var array |
||
49 | */ |
||
50 | protected $settings = array(); |
||
51 | |||
52 | /** |
||
53 | * @param Logger $logger |
||
54 | * @param CurrencyModel $currency |
||
55 | * @param CurlHelper $curl |
||
56 | */ |
||
57 | public function __construct(Logger $logger, CurrencyModel $currency, |
||
66 | |||
67 | /** |
||
68 | * Performs GET request to Yahoo API |
||
69 | * @param array $query |
||
70 | * @return array |
||
71 | */ |
||
72 | protected function request(array $query) |
||
89 | |||
90 | /** |
||
91 | * Updated store currencies |
||
92 | * @param array $settings |
||
93 | * @return array |
||
94 | */ |
||
95 | public function update(array $settings) |
||
137 | |||
138 | /** |
||
139 | * Prepares rate value before updating |
||
140 | * @param float $rate |
||
141 | * @return float |
||
142 | */ |
||
143 | protected function prepareRate($rate) |
||
151 | |||
152 | /** |
||
153 | * Whether the currency should be updated |
||
154 | * @param float $value |
||
155 | * @param array $currency |
||
156 | * @param array $derivation |
||
157 | * @return bool |
||
158 | */ |
||
159 | protected function shouldUpdateRate($value, $currency, array $derivation) |
||
180 | |||
181 | /** |
||
182 | * Returns an array of currency codes to be updated |
||
183 | * @return array |
||
184 | */ |
||
185 | public function getCandidates() |
||
212 | |||
213 | /** |
||
214 | * Returns an array of query data |
||
215 | * @param array $codes |
||
216 | * @return array |
||
217 | */ |
||
218 | protected function buildQuery(array $codes) |
||
234 | |||
235 | } |
||
236 |