Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/integrate-sdk #34

Merged
merged 7 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
aaronbrethorst marked this conversation as resolved.
Show resolved Hide resolved
}
}
2 changes: 2 additions & 0 deletions src/components/oba/StopPane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,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.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the error() method here function function like an exception? i.e. does it interrupt control flow?

Copy link
Member Author

@Ahmedhossamdev Ahmedhossamdev Aug 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git

I don't know, I tried it now, and it seems not interrupt the flow, but when I enter the stop route endpoint, the error message appears in the top

image

https://learn.svelte.dev/tutorial/error-basics

but according to svelte docs the expected error message is shown to the user.

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);
}
Loading