Giter Site home page Giter Site logo

chrispanag / oasa-telematics-api Goto Github PK

View Code? Open in Web Editor NEW
22.0 4.0 2.0 481 KB

The Athens' bus telematics API, complete with types and helper methods ๐ŸšŒ ๐ŸšŒ ๐ŸšŒ

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

License: MIT License

TypeScript 100.00%
athens greece buses telematics oasa-telematics api-client api telematics-api hacktoberfest2020 hacktoberfest

oasa-telematics-api's Introduction

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

import { APIRequests, APIHelpers } from 'oasa-telematics-api';

const api = new APIRequests();
const b = new APIHelpers();

(async () => {
    // You can fetch all the lines:
    console.log("You can fetch all the lines...");
    console.log(await api.webGetLines());

    // You can fetch a single line:
    console.log("You can fetch a single line...");
    console.log(await b.findLine('140'));

    // You can fetch a stop of a line:
    console.log("You can fetch a stop of a line...");
    const line = await b.findLine('140');
    if (line) {
        const { directions } = await b.getDirectionsOfLine(line.LineCode)
        const [come, go ] = directions;
        console.log(await b.findStop('LAMIAS', come.RouteCodes));

        // Or in greek
        console.log("Or by searching in Greek...");
        console.log(await b.findStop('ฮ›ฮ‘ฮœฮ™ฮ‘ฮฃ', come.RouteCodes));

        // Or by searching with a typo
        console.log("Or by searching with a typo...");
        console.log(await b.findStop('ฮ›ฮ‘ฮœฮ™ฮ‘', come.RouteCodes));

        // And then you can check which buses are passing through that stop:
        console.log("And then you can check which buses are passing through that stop...");
        const stops = await b.findStop('ฮ›ฮ‘ฮœฮ™ฮ‘', come.RouteCodes);
        if (stops.length > 0) {
            console.log(await api.getStopArrivals(stops[0].StopCode));
        }
    }
})();

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:

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

oasa-telematics-api's People

Contributors

chrispanag avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

wtfmejt treboryx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.