https://github.com/bttmly/bart
An ergonomic JavaScript client for the BART XML API
https://github.com/bttmly/bart
Last synced: 3 months ago
JSON representation
An ergonomic JavaScript client for the BART XML API
- Host: GitHub
- URL: https://github.com/bttmly/bart
- Owner: bttmly
- Created: 2016-02-14T03:04:56.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-05-31T17:15:57.000Z (almost 7 years ago)
- Last Synced: 2025-01-08T22:02:30.524Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 89.8 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# bart
A small JavaScript wrapper around the [BART XML API](http://api.bart.gov/docs/overview/index.aspx). Works in web browsers and Node.js.
## Installation & Usage
The name `bart` was taken, so...
`npm install --save bay-area-rapid-transit`
#### Basic usage
```js
const Bart = require("bay-area-rapid-transit")
const client = new Bart("MY_API_KEY")
```#### Configuring `fetch`
When using this module in Node.js, you must either provide a global `fetch` that is compatible with the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API), or pass a fetch function to the client at initialization time.```js
const { fetch } = require("fetch-ponyfill")() // https://github.com/qubyte/fetch-ponyfill
const Bart = require("bay-area-rapid-transit")
const client = new Bart({ key: "MY_API_KEY", fetch })
```Alternately, you can call methods directly on the `Bart` object if you provide the API key as `key` in params. Each method takes an object of params as the first argument and an optional callback as the second. If no callback is provided, a promise is returned.
Supports the following methods, which map directly to the BART API endpoints:
- `advisories`
- `trainCount`
- `elevatorInformation`
- `realTimeEstimates`
- `routes`
- `routesInformation`
- `quickPlannerArrive`
- `quickPlannerDepart`
- `fare`
- `holidays`
- `loadFactor`
- `routeSchedule`
- `availableSchedules`
- `specialSchedules`
- `stationSchedule`
- `stationList`
- `stationInformation`
- `stationAccessInformation``test/index.js` has integration tests for each method and schemas against which the responses are validated. More documentation may eventually be added to this readme but the test file should suffice for most uses.