Skip to content

Commit

Permalink
Module now a PAC-Complaint-specific wrapper for Archaeologist
Browse files Browse the repository at this point in the history
  • Loading branch information
mdb committed Feb 19, 2013
1 parent 17bae2e commit 7fd22a9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 37 deletions.
35 changes: 7 additions & 28 deletions lib/phl_pac_complaints.js
@@ -1,35 +1,14 @@
var request = require('request'),
_ = require('underscore'),
helpers = require('./helpers');
Arc = require('archaeologist');

function PhlPacComplaints(opts) {
this.defaultSettings = {
module.exports = function(opts) {
var defaultSettings = {
apiHost: "http://gis.phila.gov",
apiPathBase: "/ArcGIS/rest/services/PhilaGov/PAC_Complaints_2009_2012/MapServer/0/query",
whereFields: ['objectid', 'age', 'race', 'sex', 'type', 'date', 'unit', 'action', 'status', 'long_', 'lat', 'shape'],
defaultResultOptions: {
returnCountOnly: false,
returnIdsOnly: false,
returnGeometry: true,
maxAllowableOffset: '',
outputSpatialReference: '',
outFields: '*'
}
};

this.settings = opts ? _.defaults(opts, this.defaultSettings) : this.defaultSettings;
}

PhlPacComplaints.prototype.get = function (params, callback) {
var paramsWithDefaults = _.defaults(params, this.settings.defaultResultOptions),
url = this.settings.apiHost + this.settings.apiPathBase + '?' + helpers.buildReqParamsString(paramsWithDefaults);
whereFields: ['objectid', 'age', 'race', 'sex', 'type', 'date', 'unit', 'action', 'status', 'long_', 'lat', 'shape']
},
settings = opts ? _.defaults(opts, defaultSettings) : defaultSettings;

request(url, function (err, response, body) {
if (err) return callback(err);
callback(null, JSON.parse(body));
});
};

module.exports = function(opts) {
return new PhlPacComplaints(opts);
return new Arc(settings);
};
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -15,7 +15,8 @@
},
"dependencies": {
"request": "*",
"underscore": "1.4.4"
"underscore": "1.4.4",
"archaeologist": "0.0.2"
},
"devDependencies": {
"mocha": "*",
Expand Down
16 changes: 8 additions & 8 deletions test/phl_pac_complaints.js
Expand Up @@ -66,16 +66,16 @@ describe("PhlPacComplaints", function() {
done();
});
});
});

it("continues to work as designed, even if the API responds with an error code of 500", function (done) {
nock("http://gis.phila.gov")
.get("/ArcGIS/rest/services/PhilaGov/PAC_Complaints_2009_2012/MapServer/0/query?foo=bar&returnCountOnly=false&returnIdsOnly=false&returnGeometry=true&maxAllowableOffset=&outputSpatialReference=&outFields=*&f=json")
.reply(500, {resp: 'fake500Response'});
it("continues to work as designed, even if the API responds with an error code of 500", function (done) {
nock("http://gis.phila.gov")
.get("/ArcGIS/rest/services/PhilaGov/PAC_Complaints_2009_2012/MapServer/0/query?foo=bar&returnCountOnly=false&returnIdsOnly=false&returnGeometry=true&maxAllowableOffset=&outputSpatialReference=&outFields=*&f=json")
.reply(500, {resp: 'fake500Response'});

phlPacComplaints.get({foo: 'bar'}, function(err, data) {
expect(data).to.eql({resp: 'fake500Response'});
done();
phlPacComplaints.get({foo: 'bar'}, function(err, data) {
expect(data).to.eql({resp: 'fake500Response'});
done();
});
});
});
});

0 comments on commit 7fd22a9

Please sign in to comment.