From 4e74e9b681219601309fc84b3ac2dc083d900fb8 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Tue, 18 Aug 2015 13:31:56 -0400 Subject: [PATCH 1/4] Whitespace --- app.js | 2 +- controller/doc.js | 8 +------- sanitiser/doc.js | 1 - test/ciao/doc/msuccess.coffee | 2 +- test/ciao/doc/success.coffee | 2 +- test/unit/controller/doc.js | 5 ++--- test/unit/run.js | 2 +- test/unit/sanitiser/doc.js | 10 +++++----- 8 files changed, 12 insertions(+), 20 deletions(-) diff --git a/app.js b/app.js index c0b72610..32b8f788 100644 --- a/app.js +++ b/app.js @@ -54,4 +54,4 @@ app.use( require('./middleware/404') ); app.use( require('./middleware/408') ); app.use( require('./middleware/500') ); -module.exports = app; \ No newline at end of file +module.exports = app; diff --git a/controller/doc.js b/controller/doc.js index 76e10c3e..42cb0069 100644 --- a/controller/doc.js +++ b/controller/doc.js @@ -1,14 +1,11 @@ - var service = { mget: require('../service/mget') }; var geojsonify = require('../helper/geojsonify').search; function setup( backend ){ - // allow overriding of dependencies backend = backend || require('../src/backend'); - + function controller( req, res, next ){ - var query = req.clean.ids.map( function(id) { return { _index: 'pelias', @@ -18,7 +15,6 @@ function setup( backend ){ }); service.mget( backend, query, function( err, docs ){ - // error handler if( err ){ return next( err ); } @@ -30,9 +26,7 @@ function setup( backend ){ // respond return res.status(200).json( geojson ); - }); - } return controller; diff --git a/sanitiser/doc.js b/sanitiser/doc.js index 07f07aa1..352777a6 100644 --- a/sanitiser/doc.js +++ b/sanitiser/doc.js @@ -1,4 +1,3 @@ - var _sanitize = require('../sanitiser/_sanitize'), sanitizers = { id: require('../sanitiser/_id'), diff --git a/test/ciao/doc/msuccess.coffee b/test/ciao/doc/msuccess.coffee index 56808be4..ae49b82a 100644 --- a/test/ciao/doc/msuccess.coffee +++ b/test/ciao/doc/msuccess.coffee @@ -13,4 +13,4 @@ json.date.should.be.within now-5000, now+5000 #? valid geojson json.type.should.equal 'FeatureCollection' -json.features.should.be.instanceof Array \ No newline at end of file +json.features.should.be.instanceof Array diff --git a/test/ciao/doc/success.coffee b/test/ciao/doc/success.coffee index 3818aca6..bd1b64bd 100644 --- a/test/ciao/doc/success.coffee +++ b/test/ciao/doc/success.coffee @@ -13,4 +13,4 @@ json.date.should.be.within now-5000, now+5000 #? valid geojson json.type.should.equal 'FeatureCollection' -json.features.should.be.instanceof Array \ No newline at end of file +json.features.should.be.instanceof Array diff --git a/test/unit/controller/doc.js b/test/unit/controller/doc.js index 0bab18f2..e9e3918b 100644 --- a/test/unit/controller/doc.js +++ b/test/unit/controller/doc.js @@ -1,4 +1,3 @@ - var setup = require('../../../controller/doc'), mockBackend = require('../mock/backend'); @@ -93,7 +92,7 @@ module.exports.tests.functional_success = function(test, common) { text: 'test name2, city2, state2' } }]; - + test('functional success (with details)', function(t) { var backend = mockBackend( 'client/mget/ok/1', function( cmd ){ t.deepEqual(cmd, { body: { docs: [ { _id: 123, _index: 'pelias', _type: 'a' } ] } }, 'correct backend command'); @@ -141,4 +140,4 @@ module.exports.all = function (tape, common) { for( var testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } -}; \ No newline at end of file +}; diff --git a/test/unit/run.js b/test/unit/run.js index 75051927..222a1836 100644 --- a/test/unit/run.js +++ b/test/unit/run.js @@ -25,4 +25,4 @@ var tests = [ tests.map(function(t) { t.all(tape, common); -}); \ No newline at end of file +}); diff --git a/test/unit/sanitiser/doc.js b/test/unit/sanitiser/doc.js index c44f8808..2f88dc0a 100644 --- a/test/unit/sanitiser/doc.js +++ b/test/unit/sanitiser/doc.js @@ -7,7 +7,7 @@ var doc = require('../../../sanitiser/doc'), defaultLengthError = function(input) { return 'invalid param \''+ input + '\': text length, must be >0'; }, defaultFormatError = 'invalid: must be of the format type:id for ex: \'geoname:4163334\'', defaultError = 'invalid param \'id\': text length, must be >0', - defaultMissingTypeError = function(input) { + defaultMissingTypeError = function(input) { var type = input.split(delimiter)[0]; return type + ' is invalid. It must be one of these values - [' + indeces.join(', ') + ']'; }, defaultClean = { ids: [ { id: '123', type: 'geoname' } ], details: true }, @@ -111,7 +111,7 @@ module.exports.tests.sanitize_details = function(test, common) { t.equal(clean.details, false, 'default details set (to false)'); t.end(); }); - }); + }); }); var valid_values = ['true', true, 1]; @@ -121,7 +121,7 @@ module.exports.tests.sanitize_details = function(test, common) { t.equal(clean.details, true, 'details set to true'); t.end(); }); - }); + }); }); var valid_false_values = ['false', false, 0]; @@ -131,7 +131,7 @@ module.exports.tests.sanitize_details = function(test, common) { t.equal(clean.details, false, 'details set to false'); t.end(); }); - }); + }); }); test('test default behavior', function(t) { @@ -196,4 +196,4 @@ module.exports.all = function (tape, common) { for( var testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } -}; \ No newline at end of file +}; From 2fce64f75a6dddbc1548430513459228a0a9a8d4 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Tue, 18 Aug 2015 16:27:19 -0400 Subject: [PATCH 2/4] Move files --- controller/{doc.js => place.js} | 0 sanitiser/{doc.js => place.js} | 0 test/ciao/{doc => place}/msuccess.coffee | 0 test/ciao/{doc => place}/success.coffee | 0 test/unit/controller/{doc.js => place.js} | 0 test/unit/sanitiser/{doc.js => place.js} | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename controller/{doc.js => place.js} (100%) rename sanitiser/{doc.js => place.js} (100%) rename test/ciao/{doc => place}/msuccess.coffee (100%) rename test/ciao/{doc => place}/success.coffee (100%) rename test/unit/controller/{doc.js => place.js} (100%) rename test/unit/sanitiser/{doc.js => place.js} (100%) diff --git a/controller/doc.js b/controller/place.js similarity index 100% rename from controller/doc.js rename to controller/place.js diff --git a/sanitiser/doc.js b/sanitiser/place.js similarity index 100% rename from sanitiser/doc.js rename to sanitiser/place.js diff --git a/test/ciao/doc/msuccess.coffee b/test/ciao/place/msuccess.coffee similarity index 100% rename from test/ciao/doc/msuccess.coffee rename to test/ciao/place/msuccess.coffee diff --git a/test/ciao/doc/success.coffee b/test/ciao/place/success.coffee similarity index 100% rename from test/ciao/doc/success.coffee rename to test/ciao/place/success.coffee diff --git a/test/unit/controller/doc.js b/test/unit/controller/place.js similarity index 100% rename from test/unit/controller/doc.js rename to test/unit/controller/place.js diff --git a/test/unit/sanitiser/doc.js b/test/unit/sanitiser/place.js similarity index 100% rename from test/unit/sanitiser/doc.js rename to test/unit/sanitiser/place.js From 167547a6c1cda52ec3a1b1ecb5a5d1839a143a18 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Tue, 18 Aug 2015 18:21:59 -0400 Subject: [PATCH 3/4] Rename doc endpoint to place --- app.js | 8 ++++---- test/ciao/place/msuccess.coffee | 4 ++-- test/ciao/place/success.coffee | 4 ++-- test/unit/controller/place.js | 4 ++-- test/unit/run.js | 4 ++-- test/unit/sanitiser/place.js | 8 ++++---- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app.js b/app.js index 32b8f788..ccdd5116 100644 --- a/app.js +++ b/app.js @@ -15,7 +15,7 @@ app.use( require('./middleware/jsonp') ); /** ----------------------- sanitisers ----------------------- **/ var sanitisers = {}; -sanitisers.doc = require('./sanitiser/doc'); +sanitisers.place = require('./sanitiser/place'); sanitisers.suggest = require('./sanitiser/suggest'); sanitisers.search = require('./sanitiser/search'); sanitisers.coarse = require('./sanitiser/coarse'); @@ -25,7 +25,7 @@ sanitisers.reverse = require('./sanitiser/reverse'); var controllers = {}; controllers.index = require('./controller/index'); -controllers.doc = require('./controller/doc'); +controllers.place = require('./controller/place'); controllers.search = require('./controller/search'); /** ----------------------- routes ----------------------- **/ @@ -33,8 +33,8 @@ controllers.search = require('./controller/search'); // api root app.get( '/', controllers.index() ); -// doc API -app.get( '/doc', sanitisers.doc.middleware, controllers.doc() ); +// place API +app.get( '/place', sanitisers.place.middleware, controllers.place() ); // suggest APIs app.get( '/suggest', sanitisers.search.middleware, controllers.search() ); diff --git a/test/ciao/place/msuccess.coffee b/test/ciao/place/msuccess.coffee index ae49b82a..5c69eab1 100644 --- a/test/ciao/place/msuccess.coffee +++ b/test/ciao/place/msuccess.coffee @@ -1,6 +1,6 @@ -#> valid doc query -path: '/doc?id=geoname:4221195&id=geoname:4193595' +#> valid place query +path: '/place?id=geoname:4221195&id=geoname:4193595' #? 200 ok response.statusCode.should.equal 200 diff --git a/test/ciao/place/success.coffee b/test/ciao/place/success.coffee index bd1b64bd..d4fdea2b 100644 --- a/test/ciao/place/success.coffee +++ b/test/ciao/place/success.coffee @@ -1,6 +1,6 @@ -#> valid doc query -path: '/doc?id=geoname:4221195' +#> valid place query +path: '/place?id=geoname:4221195' #? 200 ok response.statusCode.should.equal 200 diff --git a/test/unit/controller/place.js b/test/unit/controller/place.js index e9e3918b..9fe9115a 100644 --- a/test/unit/controller/place.js +++ b/test/unit/controller/place.js @@ -1,4 +1,4 @@ -var setup = require('../../../controller/doc'), +var setup = require('../../../controller/place'), mockBackend = require('../mock/backend'); module.exports.tests = {}; @@ -14,7 +14,7 @@ module.exports.tests.interface = function(test, common) { // functionally test controller (backend success) module.exports.tests.functional_success = function(test, common) { - // expected geojson features for 'client/doc/ok/1' fixture + // expected geojson features for 'client/place/ok/1' fixture var expected = [{ type: 'Feature', geometry: { diff --git a/test/unit/run.js b/test/unit/run.js index 222a1836..96e146cf 100644 --- a/test/unit/run.js +++ b/test/unit/run.js @@ -4,14 +4,14 @@ var common = {}; var tests = [ require('./controller/index'), - require('./controller/doc'), + require('./controller/place'), require('./controller/search'), require('./service/mget'), require('./service/search'), require('./sanitiser/suggest'), require('./sanitiser/search'), require('./sanitiser/reverse'), - require('./sanitiser/doc'), + require('./sanitiser/place'), require('./sanitiser/coarse'), require('./query/indeces'), require('./query/sort'), diff --git a/test/unit/sanitiser/place.js b/test/unit/sanitiser/place.js index 2f88dc0a..03456765 100644 --- a/test/unit/sanitiser/place.js +++ b/test/unit/sanitiser/place.js @@ -1,7 +1,7 @@ -var doc = require('../../../sanitiser/doc'), - _sanitize = doc.sanitize, - middleware = doc.middleware, +var place = require('../../../sanitiser/place'), + _sanitize = place.sanitize, + middleware = place.middleware, indeces = require('../../../query/indeces'), delimiter = ':', defaultLengthError = function(input) { return 'invalid param \''+ input + '\': text length, must be >0'; }, @@ -190,7 +190,7 @@ module.exports.tests.middleware_success = function(test, common) { module.exports.all = function (tape, common) { function test(name, testFunction) { - return tape('SANTIZE /doc ' + name, testFunction); + return tape('SANTIZE /place ' + name, testFunction); } for( var testCase in module.exports.tests ){ From a976b7b258a587478ad6c91bc27869e827209a1a Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Tue, 18 Aug 2015 18:25:07 -0400 Subject: [PATCH 4/4] Add places endpoint to API docs --- DOCS.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/DOCS.md b/DOCS.md index 57f742dc..a75b044a 100644 --- a/DOCS.md +++ b/DOCS.md @@ -89,14 +89,15 @@ The reverse geocoding endpoint; matches a point on the planet to the name of tha * `details` (default: `true`) -## /doc +## /place -The endpoint for retrieving one or more elasticsearch documents with specific ids. +The endpoint for retrieving one or more places with specific ids. These correspond +directly with Elasticsearch documents. #### Required Parameters * one of `id` or `ids` * `id`: - * unique id of the document to be retrieved + * unique id of the places to be retrieved * should be in the form of type:id, for example: `geoname:4163334` * `ids`: - * if multiple docs are to be fetched in bulk, an array of ids + * if multiple places are to be fetched in bulk, an array of ids