[gnome-maps/wip/mlundblad/transit-plugin-gometro: 1/4] openTripPlanner: Refactor-out methods to create plan URLs



commit 361eecc2a085727c736100e098735485a7909077
Author: Marcus Lundblad <ml update uu se>
Date:   Tue Feb 4 22:48:46 2020 +0100

    openTripPlanner: Refactor-out methods to create plan URLs
    
    Create methods to provide the URL for creating the plan call
    to enable specialized plugins to override them if needed.

 src/transitplugins/openTripPlanner.js | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
---
diff --git a/src/transitplugins/openTripPlanner.js b/src/transitplugins/openTripPlanner.js
index 21954c24..62edd2ac 100644
--- a/src/transitplugins/openTripPlanner.js
+++ b/src/transitplugins/openTripPlanner.js
@@ -489,10 +489,8 @@ var OpenTripPlanner = class OpenTripPlanner {
         return params;
     }
 
-    _fetchPlan(params, callback) {
-        let query = new HTTP.Query(params);
-        let uri = new Soup.URI(this._getRouterUrl() + '/plan?' +
-                               query.toString());
+    _fetchPlan(url, callback) {
+        let uri = new Soup.URI(url);
         let request = new Soup.Message({ method: 'GET', uri: uri });
 
         request.request_headers.append('Accept', 'application/json');
@@ -514,6 +512,20 @@ var OpenTripPlanner = class OpenTripPlanner {
         });
     }
 
+    _getPlanUrlFromParams(params) {
+        let query = new HTTP.Query(params);
+
+        return this._getRouterUrl() + '/plan?' + query.toString();
+    }
+
+    _getPlanUrlWithStops(stops) {
+        return this._getPlanUrlFromParams(this._createParamsWithStops(stops));
+    }
+
+    _getPlanUrlWithLocations() {
+        return this._getPlanUrlFromParams(this._createParamsWithLocations());
+    }
+
     _fetchRoutes(callback) {
         if (this._onlyTransitData) {
             this._fetchTransitStops((stops) => {
@@ -535,14 +547,10 @@ var OpenTripPlanner = class OpenTripPlanner {
                     return;
                 }
 
-                let params = this._createParamsWithStops(stops);
-
-                this._fetchPlan(params, callback);
+                this._fetchPlan(this._getPlanUrlWithStops(stops), callback);
             });
         } else {
-            let params = this._createParamsWithLocations();
-
-            this._fetchPlan(params, callback);
+            this._fetchPlan(this._getPlanUrlWithLocations(), callback);
         }
     }
 


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