summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Lundblad <ml@update.uu.se>2022-02-12 08:29:55 +0100
committerMarcus Lundblad <ml@dfupdate.se>2022-03-25 22:02:43 +0100
commitf50f29e926e9410144f03a4cd75a2803cd60a252 (patch)
tree4ca995b12259595eb59cde7e127d36b3a64c7d95
parentba0090d0fcf6a0ba32b81209bef124dd178c2636 (diff)
downloadgnome-maps-wip/mlundblad/resrobot-v21.tar.gz
resrobot: Update to v2.1 APIwip/mlundblad/resrobot-v21
The Swedish Resrobot service has announced an updated API version (2.1) replacing the current v2. https://www.trafiklab.se/api/trafiklab-apis/resrobot-v21/migration-guide/ Upgrade the plugin to the new API version.
-rw-r--r--src/transitplugins/resrobot.js25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/transitplugins/resrobot.js b/src/transitplugins/resrobot.js
index 3cdd095f..d7c87e98 100644
--- a/src/transitplugins/resrobot.js
+++ b/src/transitplugins/resrobot.js
@@ -39,7 +39,7 @@ const TransitPlan = imports.transitPlan;
const Utils = imports.utils;
const BASE_URL = 'https://api.resrobot.se';
-const API_VERSION = 'v2';
+const API_VERSION = 'v2.1';
// Timezone for timestamps returned by this provider
const NATIVE_TIMEZONE = 'Europe/Stockholm';
@@ -93,11 +93,11 @@ var Resrobot = class Resrobot {
this._session = new Soup.Session({ user_agent : 'gnome-maps/' + pkg.version });
this._plan = Application.routingDelegator.transitRouter.plan;
this._query = Application.routeQuery;
- this._key = params.key;
+ this._accessId = params.accessId;
this._tz = GLib.TimeZone.new(NATIVE_TIMEZONE);
- if (!this._key)
- throw new Error('missing key');
+ if (!this._accessId)
+ throw new Error('missing accessId');
}
fetchFirstResults() {
@@ -147,14 +147,14 @@ var Resrobot = class Resrobot {
} else {
try {
let result = JSON.parse(message.response_body.data);
- let stopLocations = result.StopLocation;
+ let stopLocations = result.stopLocationOrCoordLocation;
Utils.debug('nearby stops: ' + JSON.stringify(result, null, 2));
- if (stopLocations && stopLocations.length > 0) {
- let stopLocation = stopLocations[0];
+ if (stopLocations?.length > 0) {
+ let extId = stopLocations[0]?.StopLocation.extId;
- this._viaId = stopLocation.id;
+ this._viaId = extId;
callback();
} else {
Utils.debug('No nearby stops found');
@@ -407,7 +407,7 @@ var Resrobot = class Resrobot {
let origin = leg.Origin;
let destination = leg.Destination;
- let product = leg.Product;
+ let product = leg.Product?.[0];
if (!origin)
throw new Error('Missing Origin element');
@@ -435,7 +435,6 @@ var Resrobot = class Resrobot {
let routeType =
isTransit ? this._getHVTCodeFromCatCode(product.catCode) : null;
let agencyName = isTransit ? product.operator : null;
- let agencyUrl = isTransit ? product.operatorUrl : null;
let polyline = this._createPolylineForLeg(leg);
let duration = leg.duration ? this._parseDuration(leg.duration) : null;
@@ -455,7 +454,6 @@ var Resrobot = class Resrobot {
distance: leg.dist,
duration: duration,
agencyName: agencyName,
- agencyUrl: agencyUrl,
agencyTimezoneOffset: tzOffset,
tripShortName: route });
@@ -552,11 +550,12 @@ var Resrobot = class Resrobot {
let originLocation = points[0].place.location;
let destLocation = points.last().place.location;
let transitOptions = this._query.transitOptions;
- let params = { key: this._key,
+ let params = { accessId: this._accessId,
originCoordLat: originLocation.latitude,
originCoordLong: originLocation.longitude,
destCoordLat: destLocation.latitude,
destCoordLong: destLocation.longitude,
+ passlist: 1,
format: 'json' };
if (!transitOptions.showAllTransitTypes)
@@ -582,7 +581,7 @@ var Resrobot = class Resrobot {
}
_getNearbyStopsQueryParams(lat, lon, num, radius) {
- let params = { key: this._key,
+ let params = { accessId: this._accessId,
originCoordLat: lat,
originCoordLong: lon,
maxNo: num,