diff --git a/public/example.html b/public/example.html
index ca01f6d..bdc7382 100644
--- a/public/example.html
+++ b/public/example.html
@@ -1,30 +1,82 @@
-
-
+
+
+
+ calco2la.to API client example
+
+
+
+
+
Search for airports
+
+
+
Calculate flight
+
+
+
-
+ const flightform = document.querySelector('#flight-search-form');
+ const flightresult = document.querySelector('#flight-output');
+
+ flightform.addEventListener('submit', async (e) => {
+ e.preventDefault();
+ flightresult.innerHTML = 'Loading…';
+ try {
+ const f = new FormData(flightform);
+ const flight = await api.estimateFlight({"flights": [{"departure": f.get('departure'), "arrival": f.get('arrival'), "passengerCount": 1, "travelClass": f.get('cabinclass'), "departureDate": f.get('departuredate')}]});
+ flightresult.innerHTML = JSON.stringify(flight, null, 2);
+ } catch (err) {
+ flightresult.innerHTML = `${err.message}`;
+ }
+ });
+
+
+
\ No newline at end of file
diff --git a/public/js/calco2lato.js b/public/js/calco2lato.js
index 9ae5299..1a7d868 100644
--- a/public/js/calco2lato.js
+++ b/public/js/calco2lato.js
@@ -17,8 +17,8 @@ export class Flight {
}
summary() {
const s = [];
- if (this.origin?.iata) s.push(this.origin.iata);
- if (this.destination?.iata) s.push(this.destination.iata);
+ if (this.departureAirport?.iata) s.push(this.departureAirport.iata);
+ if (this.arrivalAirport?.iata) s.push(this.arrivalAirport.iata);
const route = s.length ? s.join(' → ') : 'Flight';
const co2 = this.emissions?.co2_total ?? this.co2 ?? null;
return co2 != null ? `${route}: ${co2} kg CO₂e` : route;
diff --git a/src/Calco2latoApiClient.php b/src/Calco2latoApiClient.php
index 978f28b..c60bf23 100644
--- a/src/Calco2latoApiClient.php
+++ b/src/Calco2latoApiClient.php
@@ -86,6 +86,6 @@ final class Calco2latoApiClient
*/
public function flightEstimate(array $params): array
{
- return $this->request('POST', '/latest/transport/flights', [], $params);
+ return $this->request('POST', '/latest/transport/flight', [], $params);
}
}