From 05337261ffb4abfb0fbbb9c775ccad0e28645692 Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Wed, 22 Oct 2014 08:35:44 -0400 Subject: Begin rewrite for new API --- active911.js | 106 ----------------------------------------------------------- 1 file changed, 106 deletions(-) delete mode 100644 active911.js (limited to 'active911.js') diff --git a/active911.js b/active911.js deleted file mode 100644 index df2e2c6..0000000 --- a/active911.js +++ /dev/null @@ -1,106 +0,0 @@ -var http = require('https'); -var querystring = require('querystring'); - -module.exports = function (app_key, api_key) { - - // this is used to run all server commands - var server_command = function (data, callback) { - - // add keys to the POST request - data.app_key = app_key; - data.api_key = api_key; - - // convert the object to a querystring for POSTing - var post = querystring.stringify(data); - - // HTTP request configuration - var options = { - host: 'access.active911.com', - port: '443', - path: '/interface/open_api.php', - method: 'POST', - headers: { - 'Content-Length': post.length - } - }; - - // set up the request - var request = http.request(options, function (res) { - - res.setEncoding('utf8'); - - var json = ''; - res.on('data', function (chunk) { - json += chunk; - }); - - res.on('end', function () { - - var response = JSON.parse(json); - - if (response.result === 'error') { - callback(response.message); - } else { - return callback(false, response.message); - } - }); - - res.on('error', function (err) { - callback(err); - }); - }); - - request.write(post); - request.end(); - - }; - - return { - - ping: function (callback) { - var options = { - 'operation': 'ping' - }; - - server_command(options, callback); - }, - - getDevice: function (device_id, callback) { - var options = { - 'operation': 'get_device', - 'device_id': device_id - }; - - server_command(options, callback); - }, - - getAlert: function (alert_id, callback) { - var options = { - 'operation': 'get_alert', - 'alert_id': alert_id - }; - - server_command(options, callback); - }, - - getLocations: function (north, south, east, west, callback) { - var options = { - 'operation': 'get_locations', - 'north': north, - 'south': south, - 'east': east, - 'west': west - }; - - // use an intermediate callback to extract the location array - server_command(options, function (err, response) { - if (err) { - return callback(err); - } else { - return callback(err, response.locations); - } - }); - } - - }; -}; -- cgit v1.2.3