mirror of https://github.com/pelias/api.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.1 KiB
42 lines
1.1 KiB
10 years ago
|
|
||
|
var responses = {};
|
||
|
responses['client/suggest/ok/1'] = function( cmd, cb ){
|
||
|
return cb( undefined, suggestEnvelope([ { value: 1 }, { value: 2 } ]) );
|
||
|
};
|
||
|
responses['client/suggest/fail/1'] = function( cmd, cb ){
|
||
|
return cb( 'a backend error occurred' );
|
||
|
};
|
||
10 years ago
|
responses['client/search/ok/1'] = function( cmd, cb ){
|
||
|
return cb( undefined, searchEnvelope([ { value: 1 }, { value: 2 } ]) );
|
||
|
};
|
||
|
responses['client/search/fail/1'] = function( cmd, cb ){
|
||
|
return cb( 'a backend error occurred' );
|
||
|
};
|
||
10 years ago
|
|
||
|
function setup( key, cmdCb ){
|
||
|
function backend( a, b ){
|
||
|
return {
|
||
|
client: {
|
||
|
suggest: function( cmd, cb ){
|
||
|
if( 'function' === typeof cmdCb ){ cmdCb( cmd ); }
|
||
|
return responses[key].apply( this, arguments );
|
||
10 years ago
|
},
|
||
|
search: function( cmd, cb ){
|
||
|
if( 'function' === typeof cmdCb ){ cmdCb( cmd ); }
|
||
|
return responses[key].apply( this, arguments );
|
||
10 years ago
|
}
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
return backend;
|
||
|
}
|
||
|
|
||
|
function suggestEnvelope( options ){
|
||
|
return { pelias: [{ options: options }]};
|
||
|
}
|
||
|
|
||
10 years ago
|
function searchEnvelope( options ){
|
||
|
return { pelias: [{ options: options }]};
|
||
|
}
|
||
|
|
||
10 years ago
|
module.exports = setup;
|