Skip to content

Commit

Permalink
Add utils for API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
maxatdetroit committed May 28, 2024
1 parent 6266063 commit 15eb842
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import moment from 'moment';
import Panel from './Panel';
import Geocoder from './Geocoder';
import Cal from './Cal';
import { buildWasteAPI } from '../utils/WasteAPI';
import './App.scss';
import '../../node_modules/leaflet/dist/leaflet.css';

Expand Down Expand Up @@ -93,7 +94,8 @@ export default class App {
}
_app.map.flyTo(tempLocation, 15);
_app.panel.currentProvider = featureCollection.features[0].properties.contractor;
fetch(`https://apis.detroitmi.gov/waste_schedule/details/${featureCollection.features[0].properties.FID}/year/${_app.year}/month/${_app.month}/`)
const wasteAPIEndpoint = buildWasteAPI(featureCollection.features[0].properties.FID, _app.year, _app.month);
fetch(wasteAPIEndpoint)
.then((res) => {
res.json().then(data => {
_app.panel.location.lat = tempLocation.lat;
Expand Down
12 changes: 12 additions & 0 deletions src/utils/WasteAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Returns the API endpoint for the City of Detroit Waste Schedule API.
* @param {number} routeNum - The number denoting the waste pickup route.
* @param {string} year - The year formatted as YYYY.
* @param {string} month - The month formatted as MM and 1-indexed.
* @returns {string} - A REST API endpoint URL.
*/
function buildWasteAPI(routeNum, year, month) {
return `https://apis.detroitmi.gov/waste_schedule/details/${routeNum}/year/${year}/month/${month}/`;
}

export {buildWasteAPI};

0 comments on commit 15eb842

Please sign in to comment.