npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vasttrafik-api

v1.1.2

Published

Mirror of the official Västtrafik Travel Planner API client for javascript

Downloads

5

Readme

Västtrafik API client 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

NodeJS (see ./example.js)

const Api = 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.LocationApi();
    const res = await api.getLocationByName({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 = 'b94ad16c-715c-3820-a321-503b0267346e';
        vasttrafik.setAccessToken(token);

        var api = new vasttrafik.LocationApi();
        api.getLocationByName({input: 'Lindholmen'}, function (error, data, res) {
            console.log(res.text);
        });
    })();
</script>

Docs

Method | Description ------------- | ------------- ArrivalBoardApi.getArrivalBoard | Return the next 20 arrivals (or less if not existing) from a given point in time or the next arrivals in a given timespan. DepartureBoardApi.getDepartureBoard | Return the next 20 departures (or less if not existing) from a given point in time or the next departures in a given timespan. GeometryApi.getGeometry | Returns the polyline for a leg. JourneyDetailApi.getJourneyDetail | Returns information about the complete route of a trip. LivemapApi.livemap | Returns the positions of all vehicles in a given bounding box LocationApi.getAllStops | Returns a list of all stops available in the journey planner. LocationApi.getLocationByName | Returns a list of possible matches in the journey planner database LocationApi.getNearbyAddress | Returns the address nearest a given coordinate. LocationApi.getNearbyStops | Returns a list of stops around a given center coordinate. SysteminfoApi.getSystemInfo | Provides information about the journey planner and the underlying data TripApi.getTrip | Calculates a trip from a specified origin to a specified destination.

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:

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

Monkey patches:

  • JSON instead of XML is returned by default (see mirror/src/ApiClient.js#448)
  • Avoids duplicate api calls when using promises (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.