Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 66078b2

Browse files
committed
v1.0.2
Signed-off-by: Finbarrs Oketunji <f@finbarrs.eu>
1 parent acd5653 commit 66078b2

File tree

4 files changed

+114
-20
lines changed

4 files changed

+114
-20
lines changed

README.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ $baseCurrency = 'GBP';
6565
$targetCurrency = 'EUR';
6666
$amount = 1000;
6767

68+
// Set the date for which you want to retrieve the currencies
69+
$day = '05';
70+
$month = '04';
71+
$year = '2023';
72+
73+
// Set the UUID of the currency you want to retrieve
74+
$uuid = 'currency_uuid';
75+
6876
// Call the convert method to perform the currency conversion
6977
$conversionResult = $currensees->convert($date, $baseCurrency, $targetCurrency, $amount);
7078
if ($conversionResult) {
@@ -82,14 +90,6 @@ if ($convertAllResult) {
8290
echo "Conversion to all currencies failed: " . $convertAllResult['error'] . "\n";
8391
}
8492

85-
// Set the date for which you want to retrieve the currencies
86-
$day = '02';
87-
$month = '04';
88-
$year = '2023';
89-
90-
// Set the UUID of the currency you want to retrieve
91-
$uuid = 'currency_uuid';
92-
9393
// Call the getCurrencies method to get the available currencies for the given date
9494
$currenciesResult = $currensees->getCurrencies($username, $day, $month, $year);
9595
if ($currenciesResult) {
@@ -107,6 +107,24 @@ if ($currencyResult) {
107107
} else {
108108
echo "Failed to retrieve currency details for the given date.\n";
109109
}
110+
111+
// Call the getHistoricalData method to get historical data for all currencies for the given date
112+
$historicalDataResult = $currensees->getHistoricalData($username, $date, $day, $month, $year);
113+
if ($historicalDataResult) {
114+
echo "Historical data for " . $date . ":\n";
115+
echo json_encode($historicalDataResult) . "\n";
116+
} else {
117+
echo "Failed to retrieve historical data for the given date.\n";
118+
}
119+
120+
// Call the getHistoricalDataForCurrency method to get historical data for a specific currency
121+
$historicalDataForCurrencyResult = $currensees->getHistoricalDataForCurrency($uuid, $username, $day, $month, $year, $date);
122+
if ($historicalDataForCurrencyResult) {
123+
echo "Historical data for currency " . $uuid . " on " . $date . ":\n";
124+
echo json_encode($historicalDataForCurrencyResult) . "\n";
125+
} else {
126+
echo "Failed to retrieve historical data for the given currency and date.\n";
127+
}
110128
?>
111129
```
112130

example.php

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
$targetCurrency = 'EUR';
2626
$amount = 1000;
2727

28+
// Set the date for which you want to retrieve the currencies
29+
$day = '05';
30+
$month = '04';
31+
$year = '2023';
32+
33+
// Set the UUID of the currency you want to retrieve
34+
$uuid = 'currency_uuid';
35+
2836
// Call the convert method to perform the currency conversion
2937
$conversionResult = $currensees->convert($date, $baseCurrency, $targetCurrency, $amount);
3038
if ($conversionResult) {
@@ -42,14 +50,6 @@
4250
echo "Conversion to all currencies failed: " . $convertAllResult['error'] . "\n";
4351
}
4452

45-
// Set the date for which you want to retrieve the currencies
46-
$day = '02';
47-
$month = '04';
48-
$year = '2023';
49-
50-
// Set the UUID of the currency you want to retrieve
51-
$uuid = 'currency_uuid';
52-
5353
// Call the getCurrencies method to get the available currencies for the given date
5454
$currenciesResult = $currensees->getCurrencies($username, $day, $month, $year);
5555
if ($currenciesResult) {
@@ -68,4 +68,21 @@
6868
echo "Failed to retrieve currency details for the given date.\n";
6969
}
7070

71+
// Call the getHistoricalData method to get historical data for all currencies for the given date
72+
$historicalDataResult = $currensees->getHistoricalData($username, $date, $day, $month, $year);
73+
if ($historicalDataResult) {
74+
echo "Historical data for " . $date . ":\n";
75+
echo json_encode($historicalDataResult) . "\n";
76+
} else {
77+
echo "Failed to retrieve historical data for the given date.\n";
78+
}
79+
80+
// Call the getHistoricalDataForCurrency method to get historical data for a specific currency
81+
$historicalDataForCurrencyResult = $currensees->getHistoricalDataForCurrency($uuid, $username, $day, $month, $year, $date);
82+
if ($historicalDataForCurrencyResult) {
83+
echo "Historical data for currency " . $uuid . " on " . $date . ":\n";
84+
echo json_encode($historicalDataForCurrencyResult) . "\n";
85+
} else {
86+
echo "Failed to retrieve historical data for the given currency and date.\n";
87+
}
7188
?>

src/currensees.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,39 @@ public function getCurrency($uuid, $username, $day, $month, $year)
108108
return false;
109109
}
110110
}
111+
112+
public function getHistoricalData($username, $date, $day, $month, $year)
113+
{
114+
$client = new Client();
115+
$headers = [
116+
'Accept' => 'application/json'
117+
];
118+
$url = 'https://currensees.com/v1/historical?username=' . $username . '&date=' . $date . '&day=' . $day . '&month=' . $month . '&year=' . $year;
119+
$request = new Request('GET', $url, $headers);
120+
$res = $client->sendAsync($request)->wait();
121+
122+
if ($res->getStatusCode() == 200) {
123+
return json_decode($res->getBody(), true);
124+
} else {
125+
return false;
126+
}
127+
}
128+
129+
public function getHistoricalDataForCurrency($uuid, $username, $day, $month, $year, $date)
130+
{
131+
$client = new Client();
132+
$headers = [
133+
'Accept' => 'application/json'
134+
];
135+
$url = 'https://currensees.com/v1/historical/' . $uuid . '?username=' . $username . '&day=' . $day . '&month=' . $month . '&year=' . $year . '&date_string=' . $date;
136+
$request = new Request('GET', $url, $headers);
137+
$res = $client->sendAsync($request)->wait();
138+
139+
if ($res->getStatusCode() == 200) {
140+
return json_decode($res->getBody(), true);
141+
} else {
142+
return false;
143+
}
144+
}
111145

112146
}

tests/CurrenseesTest.php

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testLogin()
2626

2727
public function testConvert()
2828
{
29-
$date = '2023_04_03';
29+
$date = '2023_04_05';
3030
$baseCurrency = 'GBP';
3131
$targetCurrency = 'EUR';
3232
$amount = 1000;
@@ -39,7 +39,7 @@ public function testConvertAll()
3939
{
4040
$baseCurrency = 'GBP';
4141
$amount = 1000;
42-
$date = '2023_04_03';
42+
$date = '2023_04_05';
4343

4444
$result = $this->currensees->convertAll($baseCurrency, $amount, $date);
4545
$this->assertTrue(is_array($result));
@@ -48,7 +48,7 @@ public function testConvertAll()
4848
public function testGetCurrencies()
4949
{
5050
$username = 'your_username';
51-
$day = '02';
51+
$day = '05';
5252
$month = '04';
5353
$year = '2023';
5454

@@ -60,11 +60,36 @@ public function testGetCurrency()
6060
{
6161
$uuid = 'currency_uuid';
6262
$username = 'your_username';
63-
$day = '02';
63+
$day = '05';
6464
$month = '04';
6565
$year = '2023';
6666

6767
$result = $this->currensees->getCurrency($uuid, $username, $day, $month, $year);
6868
$this->assertTrue(is_array($result));
6969
}
70+
71+
public function testGetHistoricalData()
72+
{
73+
$username = 'your_username';
74+
$date = '2023_04_05';
75+
$day = '05';
76+
$month = '04';
77+
$year = '2023';
78+
79+
$result = $this->currensees->getHistoricalData($username, $date, $day, $month, $year);
80+
$this->assertTrue(is_array($result));
81+
}
82+
83+
public function testGetHistoricalDataForCurrency()
84+
{
85+
$uuid = 'currency_uuid';
86+
$username = 'your_username';
87+
$day = '05';
88+
$month = '04';
89+
$year = '2023';
90+
$date = '2023_04_05';
91+
92+
$result = $this->currensees->getHistoricalDataForCurrency($uuid, $username, $day, $month, $year, $date);
93+
$this->assertTrue(is_array($result));
94+
}
7095
}

0 commit comments

Comments
 (0)