项目作者: chrispanag

项目描述 :
The Athens' bus telematics API, complete with types and helper methods 🚌 🚌 🚌
高级语言: TypeScript
项目地址: git://github.com/chrispanag/oasa-telematics-api.git
创建时间: 2020-09-19T10:27:11Z
项目社区:https://github.com/chrispanag/oasa-telematics-api

开源协议:MIT License

下载


OASA Telematics API

npm npm GitHub Workflow Status

The (unofficial) Telematics API of Athens’ public buses, complete with types and helper methods 🚌🚌🚌

This is the package that powers the popular greek messenger bot “Πότε έρχεται το λεωφορείο μου 🚌“.

Getting Started

Install the package: $ npm i oasa-telematics-api

  1. import { APIRequests, APIHelpers } from 'oasa-telematics-api';
  2. const api = new APIRequests();
  3. const b = new APIHelpers();
  4. (async () => {
  5. // You can fetch all the lines:
  6. console.log("You can fetch all the lines...");
  7. console.log(await api.webGetLines());
  8. // You can fetch a single line:
  9. console.log("You can fetch a single line...");
  10. console.log(await b.findLine('140'));
  11. // You can fetch a stop of a line:
  12. console.log("You can fetch a stop of a line...");
  13. const line = await b.findLine('140');
  14. if (line) {
  15. const { directions } = await b.getDirectionsOfLine(line.LineCode)
  16. const [come, go ] = directions;
  17. console.log(await b.findStop('LAMIAS', come.RouteCodes));
  18. // Or in greek
  19. console.log("Or by searching in Greek...");
  20. console.log(await b.findStop('ΛΑΜΙΑΣ', come.RouteCodes));
  21. // Or by searching with a typo
  22. console.log("Or by searching with a typo...");
  23. console.log(await b.findStop('ΛΑΜΙΑ', come.RouteCodes));
  24. // And then you can check which buses are passing through that stop:
  25. console.log("And then you can check which buses are passing through that stop...");
  26. const stops = await b.findStop('ΛΑΜΙΑ', come.RouteCodes);
  27. if (stops.length > 0) {
  28. console.log(await api.getStopArrivals(stops[0].StopCode));
  29. }
  30. }
  31. })();

You can explore more by visiting the (mostly auto-generated) docs here:

https://chrispanag.github.io/oasa-telematics-api/

Also, feel free to open an issue if you want to ask or suggest anything :)

Can I use my own request method?

Yes. The constructors APIRequests and APIHelpers can get a request function as an argument.

The request function will need to have the form:

  1. export type RequestFunction = <T>(url: string, query: string, ...params: any[]) => Promise<T>;

You can see a reference request function here.

Why would I want to use my own request method?

Caching.

Also, see below…

Can I use this for frontend development?

Yes. But you’ll need to create a custom request function using the browser fetch method instead of the default one installed (node-fetch). You can see the above question for more details.

Next Steps

  • Add tests
  • Add some more helper methods for schedule management