Coder Social home page Coder Social logo

simonbengtsson / vasttrafik-api Goto Github PK

View Code? Open in Web Editor NEW
16.0 7.0 4.0 635 KB

Mirror of the official Västtrafik API (reseplaneraren) for JavaScript

Home Page: https://developer.vasttrafik.se/portal/#/api/Reseplaneraren/v2/landerss

License: The Unlicense

HTML 0.13% JavaScript 99.68% Shell 0.19%
vasttrafik mirror

vasttrafik-api's Introduction

Västtrafik API for JavaScript

This is a mirror of the official Västtrafik Travel Planner API Client for Javascript. For more information, see the official api website.

Usage

Below is an example of how to use the LocationsApi endpoint. See all endpoints in ./mirror/README.md or https://developer.vasttrafik.se/apis/13/v4

NodeJS (see ./example.js)

const vasttrafik = require("vasttrafik-api");

// Sample credentials. Be sure to get your own before going into production.
(async () => {
  const key = "8aOzt2RmMIG0OXSyIgjM2IkHvAoa";
  const secret = "OMxjxjaXblXdpn8E1gYFehHyx3Ea";
  await vasttrafik.authorize(key, secret);

  const api = new vasttrafik.LocationsApi();
  const res = await api.locationsByTextGet({ input: "Lindholmen" });
  console.log(res.text);
})();

Browsers (see ./example.html)

<script src="./dist/vasttrafik.js"></script>
<script>
  (function () {
    // Sample token. Generate access token on server (see example.js)
    var token = "eyJ4NXQiOiJaV05sTURNNE56SmpZ...";
    vasttrafik.setAccessToken(token);

    var api = new vasttrafik.LocationsApi();
    api
      .locationsByTextGet({ input: "Lindholmen" })
      .then(function (error, data, res) {
        console.log(res.text);
      });
  })();
</script>

Authentication

If you just want to test things out you can use these sample credentials:

key '8aOzt2RmMIG0OXSyIgjM2IkHvAoa' secret 'OMxjxjaXblXdpn8E1gYFehHyx3Ea'

Don't forget to create your own credentials in the developer portal before going into production however since the sample ones might become invalid at any time.

Changes

This repository is mostly a simple mirror of the official api client, but a few changes were made to make it easier to work with.

Helper methods added:

  • vasttrafik.authorize(key, secret, deviceId) Fetches an access token with the specified key and secret (cannot be used in the browser)
  • vasttrafik.setAccessToken(token) Authorizes upcoming api calls with the specified access token (obtained with authorize)

Three patches applied to APIClient.js (commented with @monkeyPatch)

  • JSON instead of XML is returned by default (see mirror/src/ApiClient.js#448)
  • Fix promise usage (see mirror/src/ApiClient.js#453)

Version

  • npm version patch|minor|major
  • npm run deploy

Questions?

You can post questions about Västtrafik's API in the developer forum. Also feel free posting issues or questions regarding this mirror here on github.

vasttrafik-api's People

Contributors

simonbengtsson avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

vasttrafik-api's Issues

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.