aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--lib/clients/refresh.js10
-rw-r--r--tests/active911.js25
3 files changed, 35 insertions, 4 deletions
diff --git a/README.md b/README.md
index daf1041..972e716 100644
--- a/README.md
+++ b/README.md
@@ -32,7 +32,9 @@ The following public API methods are available:
* `getAgency()`
* `getDevice(device_id)`
-* `getAlerts()`
+* `getAlerts({ alert_days: 1, alert_minutes: 30 })`, where the object parameter
+ is optional. You should not use both keys; if `alert_minutes` is provided, it
+ will override `alert_days` as documented [on the wiki](http://wiki.active911.com/wiki/index.php/Accessing_the_API#Alerts).
* `getDeviceAlerts(device_id)`
* `getAlert(alert_id)`
* `getLocations()`
diff --git a/lib/clients/refresh.js b/lib/clients/refresh.js
index 7b9fde7..a88d899 100644
--- a/lib/clients/refresh.js
+++ b/lib/clients/refresh.js
@@ -92,8 +92,14 @@ RefreshClient.prototype.getDevice = function(id) {
return this._doRequest('/devices/' + id);
};
-RefreshClient.prototype.getAlerts = function() {
- return this._doRequest('/alerts');
+RefreshClient.prototype.getAlerts = function(options) {
+ var url = '/alerts';
+ if (options && options.alert_minutes) {
+ url += '?alert_minutes=' + options.alert_minutes;
+ } else if (options && options.alert_days) {
+ url += '?alert_days=' + options.alert_days;
+ }
+ return this._doRequest(url);
};
RefreshClient.prototype.getAlert = function(id) {
diff --git a/tests/active911.js b/tests/active911.js
index 0aa9ffa..de91f1c 100644
--- a/tests/active911.js
+++ b/tests/active911.js
@@ -17,7 +17,7 @@ var resourceResponse = require('./replies/resource.json');
var errorResponse = require('./replies/error.json');
var nockPath = function(path, response) {
- nock('https://access.active911.com')
+ return nock('https://access.active911.com')
.get('/interface/open_api/api' + path)
.reply(200, response);
};
@@ -136,3 +136,26 @@ describe('Active911 API', function() {
});
});
});
+
+describe('Alert filtering', function() {
+ it('should request alerts filtered by alert_days', function(done) {
+ var n = nockPath('/alerts?alert_days=1', alertsResponse);
+ client.getAlerts({ alert_days: 1}).then(function() {
+ n.isDone().should.be.true;
+ done();
+ }).catch(function(err) {
+ false.should.be.true;
+ done();
+ });
+ });
+ it('should request alerts filtered by alert_minutes', function(done) {
+ var n = nockPath('/alerts?alert_minutes=1', alertsResponse);
+ client.getAlerts({ alert_minutes: 1}).then(function() {
+ n.isDone().should.be.true;
+ done();
+ }).catch(function(err) {
+ false.should.be.true;
+ done();
+ });
+ });
+});