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');
(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() {
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
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.