1 | <?php |
||
14 | class Client |
||
15 | { |
||
16 | // Client constants |
||
17 | const API_URL_ENDPOINT = 'http://openexchangerates.org/api/'; |
||
18 | const API_FILE_LATEST = 'latest.json'; |
||
19 | const API_FILE_CURRENCIES = 'currencies.json'; |
||
20 | const API_FOLDER_HISTORICAL = 'historical'; |
||
21 | const OPTION_APP_ID = 'appId'; |
||
22 | |||
23 | /** |
||
24 | * The App ID required to enable connectivity |
||
25 | * |
||
26 | * @var string |
||
27 | * @see https://openexchangerates.org/documentation#app-ids |
||
28 | */ |
||
29 | private $appId; |
||
30 | |||
31 | /** |
||
32 | * Client constructor method to initialise the client |
||
33 | * |
||
34 | * @param array $options |
||
35 | */ |
||
36 | public function __construct($options = array()) |
||
43 | |||
44 | |||
45 | /** |
||
46 | * Getter method to retrieve the configured App ID |
||
47 | * |
||
48 | * @see https://openexchangerates.org/documentation#app-ids |
||
49 | * @return string |
||
50 | */ |
||
51 | public function getAppId() |
||
55 | |||
56 | /** |
||
57 | * Setter method to configure the client App ID |
||
58 | * - Login to your account to retrieve your App Id |
||
59 | * |
||
60 | * @see https://openexchangerates.org/documentation#app-ids |
||
61 | * @param string $appId |
||
62 | * @return OpenExchange\Client |
||
63 | */ |
||
64 | public function setAppId($appId) |
||
72 | |||
73 | /** |
||
74 | * Method to retrieve the latest currency rate information |
||
75 | * |
||
76 | * @see https://openexchangerates.org/documentation#accessing-the-api |
||
77 | * @return stdClass |
||
78 | */ |
||
79 | public function getLatest() |
||
92 | |||
93 | /** |
||
94 | * Method to retrieve the currency list available from the API |
||
95 | * |
||
96 | * @see https://openexchangerates.org/documentation#accessing-the-api |
||
97 | * @return stdClass |
||
98 | */ |
||
99 | public function getCurrencies() |
||
112 | |||
113 | /** |
||
114 | * Method to retrieve the historical rate information for a given date |
||
115 | * |
||
116 | * @see https://openexchangerates.org/documentation#historical-data |
||
117 | * @param \DateTime $date |
||
118 | * @return stdClass |
||
119 | */ |
||
120 | public function getHistorical(\DateTime $date) |
||
133 | |||
134 | /** |
||
135 | * Helper function to retrieve the relative file path to historical rate |
||
136 | * json files on the open exchange server. |
||
137 | * |
||
138 | * @param \DateTime $date |
||
139 | * @return string |
||
140 | */ |
||
141 | private function getHistoricalFilePath(\DateTime $date) |
||
145 | |||
146 | /** |
||
147 | * Helper method to perform a cURL request to the API for a given URL's data |
||
148 | * |
||
149 | * @param string $url |
||
150 | * @return stdClass |
||
151 | */ |
||
152 | private function getCurlResponse($url) |
||
165 | } |
||
166 |