[gnome-maps/wip/mlundblad/transit-routing: 1/2] WIP: Add module to query an OpenTripPlanner instance



commit be75554b55b512a0d165201ba49d360336cccdb3
Author: Marcus Lundblad <ml update uu se>
Date:   Mon Feb 15 23:18:14 2016 +0100

    WIP: Add module to query an OpenTripPlanner instance

 src/openTripPlanner.js               |   55 ++++++++++++++++++++++++++++++++++
 src/org.gnome.Maps.src.gresource.xml |    1 +
 2 files changed, 56 insertions(+), 0 deletions(-)
---
diff --git a/src/openTripPlanner.js b/src/openTripPlanner.js
new file mode 100644
index 0000000..12c44d0
--- /dev/null
+++ b/src/openTripPlanner.js
@@ -0,0 +1,55 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2016 Marcus Lundblad
+ *
+ * GNOME Maps is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with GNOME Maps; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Author: Marcus Lundblad <ml update uu se>
+ */
+
+const Lang = imports.lang;
+
+const Soup = imports.gi.Soup;
+
+const RouteQuery = imports.routeQuery;
+const Utils = imports.utils;
+
+/* base URL used for testing against a local OTP instance for now */
+const _BASE_URL = 'http://localhost:8080/otp';
+
+const OpenTripPlanner = new Lang.Class({
+    Name: 'OpenTripPlanner',
+
+    _init: function() {
+        this._session = new Soup.Session();
+    },
+
+    fetchRouters: function(callback) {
+        let uri = new Soup.URI(_BASE_URL + '/routers');
+        let request = new Soup.Message({ method: 'GET', uri: uri });
+
+        request.request_headers.append('Accept', 'application/json');
+        this._session.queue_message(request, (function(obj, message) {
+            if (message.status_code !== Soup.Status.OK) {
+                callback(false, message.status_code);
+                return;
+            }
+
+            Utils.debug('routers: ' + message.response_body.data);
+
+        }).bind(this));
+    }
+})
diff --git a/src/org.gnome.Maps.src.gresource.xml b/src/org.gnome.Maps.src.gresource.xml
index 9545af1..8a245a0 100644
--- a/src/org.gnome.Maps.src.gresource.xml
+++ b/src/org.gnome.Maps.src.gresource.xml
@@ -32,6 +32,7 @@
     <file>mapView.js</file>
     <file>mapWalker.js</file>
     <file>notification.js</file>
+    <file>openTripPlanner.js</file>
     <file>notificationManager.js</file>
     <file>osmAccountDialog.js</file>
     <file>osmConnection.js</file>


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