Skip to content

Commit

Permalink
Merge pull request #34 from OneBusAway/feature/integrate-sdk
Browse files Browse the repository at this point in the history
Feature/integrate-sdk
  • Loading branch information
aaronbrethorst authored Aug 21, 2024
2 parents c5fec32 + 2a6cbf2 commit f16738a
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 36 deletions.
197 changes: 175 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
},
"type": "module",
"dependencies": {
"@fortawesome/free-regular-svg-icons": "^6.6.0"
"@fortawesome/free-regular-svg-icons": "^6.6.0",
"onebusaway-sdk": "^0.1.0-alpha.31"
}
}
2 changes: 2 additions & 0 deletions src/components/oba/StopPane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
async function loadData(stopID) {
loading = true;
const response = await fetch(`/api/oba/arrivals-and-departures-for-stop/${stopID}`);
if (response.ok) {
arrivalsAndDeparturesResponse = await response.json();
arrivalsAndDepartures = arrivalsAndDeparturesResponse.data.entry;
Expand Down
17 changes: 10 additions & 7 deletions src/lib/RestAPI/arrivalsAndDeparturesForStop.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { error, json } from '@sveltejs/kit';

import { PUBLIC_OBA_SERVER_URL as baseURL } from '$env/static/public';
import { PRIVATE_OBA_API_KEY as apiKey } from '$env/static/private';

import onebusaway from 'onebusaway-sdk';

const oba = new onebusaway({
baseURL,
apiKey
});

export default async function (stopID) {
const apiURL = `${baseURL}/api/where/arrivals-and-departures-for-stop/${stopID}.json?key=${apiKey}`;
const response = await fetch(apiURL);
const response = await oba.arrivalAndDeparture.list(stopID);

if (!response.ok) {
if (response.code !== 200) {
error(500, 'Unable to fetch arrivals-and-departures-for-stop.');
return;
}

const data = await response.json();
return json(data);
return json(response);
}
16 changes: 10 additions & 6 deletions src/lib/RestAPI/stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ import { error, json } from '@sveltejs/kit';

import { PUBLIC_OBA_SERVER_URL as baseURL } from '$env/static/public';
import { PRIVATE_OBA_API_KEY as apiKey } from '$env/static/private';
import onebusaway from 'onebusaway-sdk';

const oba = new onebusaway({
baseURL,
apiKey
});

export default async function (stopID) {
const apiURL = `${baseURL}/api/where/stop/${stopID}.json?key=${apiKey}`;
const response = await fetch(apiURL);
const response = await oba.stop.retrieve(stopID);

if (!response.ok) {
return error(500, 'Unable to fetch arrivals-and-departures-for-stop.');
if (response.code !== 200) {
error(500, 'Unable to fetch arrivals-and-departures-for-stop.');
}

const data = await response.json();
return json(data);
return json(response);
}

0 comments on commit f16738a

Please sign in to comment.