[gnome-maps/wip/routing: 2/2] Add abstract RouteService class



commit c52d38a984ffdfe69c582b2adb0346d518e3502f
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Fri Aug 23 06:15:55 2013 +0200

    Add abstract RouteService class
    
    The RouteService class is meant as a base class for
    route service classes.

 src/routeService.js |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/src/routeService.js b/src/routeService.js
new file mode 100644
index 0000000..6f36b63
--- /dev/null
+++ b/src/routeService.js
@@ -0,0 +1,51 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2013 Mattias Bengtsson.
+ *
+ * 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: Mattias Bengtsson <mattias jc bengtsson gmail com>
+ */
+
+const Soup = imports.gi.Soup;
+
+const Lang = imports.lang;
+
+const RouteService = new Lang.Class({
+    Name: 'RouteService',
+    Abstract: true,
+
+    _init: function() {
+        this._session = new Soup.SessionAsync({ user_agent : "gnome-maps " });
+    },
+
+    _buildURL: function() {},
+
+    _parseResult: function(result) {},
+
+    request: function(viaPoints, callback) {
+        let request = new Soup.Message('GET', this._buildURL(viaPoints));
+        this._session.queue_message(request, (function(session, message) {
+            if (message.status_code === 200) {
+                let result = message.response_body.data;
+                callback(this._parseResult(result));
+            } else {
+                log("Error: " + message.status_code);
+                callback(null);                
+            }
+        }).bind(this));
+    }
+});


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