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

Commit 1f88cd3

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

File tree

4 files changed

+104
-1
lines changed

4 files changed

+104
-1
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ $year = '2023';
7373
// Set the UUID of the currency you want to retrieve
7474
$uuid = 'currency_uuid';
7575

76+
// Set the date for which you want to retrieve the daily average
77+
$dailyAverageDate = '2023_04_10';
78+
79+
// Set the date range for which you want to retrieve the weekly average
80+
$weeklyAverageFromDate = '2023_04_03';
81+
$weeklyAverageToDate = '2023_04_07';
82+
7683
// Call the convert method to perform the currency conversion
7784
$conversionResult = $currensees->convert($date, $baseCurrency, $targetCurrency, $amount);
7885
if ($conversionResult) {
@@ -125,6 +132,24 @@ if ($historicalDataForCurrencyResult) {
125132
} else {
126133
echo "Failed to retrieve historical data for the given currency and date.\n";
127134
}
135+
136+
// Call the getDailyAverage method to get the daily average for the given date
137+
$dailyAverageResult = $currensees->getDailyAverage($dailyAverageDate);
138+
if ($dailyAverageResult) {
139+
echo "Daily average for " . $dailyAverageDate . ":\n";
140+
echo json_encode($dailyAverageResult) . "\n";
141+
} else {
142+
echo "Failed to retrieve daily average for the given date.\n";
143+
}
144+
145+
// Call the getWeeklyAverage method to get the weekly average for the given date range
146+
$weeklyAverageResult = $currensees->getWeeklyAverage($weeklyAverageFromDate, $weeklyAverageToDate);
147+
if ($weeklyAverageResult) {
148+
echo "Weekly average from " . $weeklyAverageFromDate . " to " . $weeklyAverageToDate . ":\n";
149+
echo json_encode($weeklyAverageResult) . "\n";
150+
} else {
151+
echo "Failed to retrieve weekly average for the given date range.\n";
152+
}
128153
?>
129154
```
130155

example.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
// Set the UUID of the currency you want to retrieve
3434
$uuid = 'currency_uuid';
3535

36+
// Set the date for which you want to retrieve the daily average
37+
$dailyAverageDate = '2023_04_10';
38+
39+
// Set the date range for which you want to retrieve the weekly average
40+
$weeklyAverageFromDate = '2023_04_03';
41+
$weeklyAverageToDate = '2023_04_07';
42+
3643
// Call the convert method to perform the currency conversion
3744
$conversionResult = $currensees->convert($date, $baseCurrency, $targetCurrency, $amount);
3845
if ($conversionResult) {
@@ -85,4 +92,22 @@
8592
} else {
8693
echo "Failed to retrieve historical data for the given currency and date.\n";
8794
}
95+
96+
// Call the getDailyAverage method to get the daily average for the given date
97+
$dailyAverageResult = $currensees->getDailyAverage($dailyAverageDate);
98+
if ($dailyAverageResult) {
99+
echo "Daily average for " . $dailyAverageDate . ":\n";
100+
echo json_encode($dailyAverageResult) . "\n";
101+
} else {
102+
echo "Failed to retrieve daily average for the given date.\n";
103+
}
104+
105+
// Call the getWeeklyAverage method to get the weekly average for the given date range
106+
$weeklyAverageResult = $currensees->getWeeklyAverage($weeklyAverageFromDate, $weeklyAverageToDate);
107+
if ($weeklyAverageResult) {
108+
echo "Weekly average from " . $weeklyAverageFromDate . " to " . $weeklyAverageToDate . ":\n";
109+
echo json_encode($weeklyAverageResult) . "\n";
110+
} else {
111+
echo "Failed to retrieve weekly average for the given date range.\n";
112+
}
88113
?>

src/currensees.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,42 @@ public function getHistoricalDataForCurrency($uuid, $username, $day, $month, $ye
141141
} else {
142142
return false;
143143
}
144-
}
144+
}
145+
146+
public function getDailyAverage($date)
147+
{
148+
$client = new Client();
149+
$headers = [
150+
'Content-Type' => 'application/json',
151+
'Accept' => 'application/json'
152+
];
153+
$body = '';
154+
$request = new Request('GET', 'https://currensees.com/v1/daily_average/' . $date, $headers, $body);
155+
$res = $client->sendAsync($request)->wait();
156+
157+
if ($res->getStatusCode() == 200) {
158+
return json_decode($res->getBody(), true);
159+
} else {
160+
return false;
161+
}
162+
}
163+
164+
public function getWeeklyAverage($from_date, $to_date)
165+
{
166+
$client = new Client();
167+
$headers = [
168+
'Content-Type' => 'application/json',
169+
'Accept' => 'application/json'
170+
];
171+
$body = '';
172+
$request = new Request('GET', 'https://currensees.com/v1/weekly_average/' . $from_date . '/' . $to_date, $headers, $body);
173+
$res = $client->sendAsync($request)->wait();
174+
175+
if ($res->getStatusCode() == 200) {
176+
return json_decode($res->getBody(), true);
177+
} else {
178+
return false;
179+
}
180+
}
145181

146182
}

tests/CurrenseesTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,21 @@ public function testGetHistoricalDataForCurrency()
9292
$result = $this->currensees->getHistoricalDataForCurrency($uuid, $username, $day, $month, $year, $date);
9393
$this->assertTrue(is_array($result));
9494
}
95+
96+
public function testGetDailyAverage()
97+
{
98+
$date = '2023_04_05';
99+
100+
$result = $this->currensees->getDailyAverage($date);
101+
$this->assertTrue(is_array($result));
102+
}
103+
104+
public function testGetWeeklyAverage()
105+
{
106+
$from_date = '2023_04_03';
107+
$to_date = '2023_04_07';
108+
109+
$result = $this->currensees->getWeeklyAverage($from_date, $to_date);
110+
$this->assertTrue(is_array($result));
111+
}
95112
}

0 commit comments

Comments
 (0)