[gnome-maps/wip/mlundblad/resrobot-v21] WIP: resrobot: Update to v2.1 API




commit fd05863c72a96b338acfb7186a6b36c8fc5f11ca
Author: Marcus Lundblad <ml update uu se>
Date:   Sat Feb 12 08:29:55 2022 +0100

    WIP: resrobot: Update to v2.1 API

 src/transitplugins/resrobot.js | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)
---
diff --git a/src/transitplugins/resrobot.js b/src/transitplugins/resrobot.js
index 3cdd095f..8fb95704 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() {
@@ -140,21 +140,21 @@ var Resrobot = class Resrobot {
                                '/location.nearbystops?' + query.toString());
         let request = new Soup.Message({ method: 'GET', uri: uri });
 
+        log('uri: ' + BASE_URL + '/' + API_VERSION +
+                               '/location.nearbystops?' + query.toString());
+
         this._session.queue_message(request, (obj, message) => {
             if (message.status_code !== Soup.Status.OK) {
-                Utils.debug('Failed to get nearby stops: ' + message.status_code);
                 this._noRouteFound();
             } else {
                 try {
                     let result = JSON.parse(message.response_body.data);
-                    let stopLocations = result.StopLocation;
-
-                    Utils.debug('nearby stops: ' + JSON.stringify(result, null, 2));
+                    let stopLocations = result.stopLocationOrCoordLocation;
 
-                    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,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]