2015-06-03 21:45:54 -07:00
|
|
|
import path from 'path';
|
|
|
|
import fs from 'fs';
|
2015-01-06 12:58:57 +00:00
|
|
|
|
|
|
|
var services = [];
|
|
|
|
|
2015-06-03 21:45:54 -07:00
|
|
|
fs.readdirSync(path.join(__dirname, 'services')).forEach(function(file) {
|
|
|
|
var service = require(path.join(__dirname, 'services', file));
|
2015-01-06 12:58:57 +00:00
|
|
|
if (service.search) {
|
|
|
|
services.push(service);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = function(url) {
|
|
|
|
|
|
|
|
var matchedService;
|
|
|
|
services.some(function(service) {
|
|
|
|
matchedService = service.match(url) ? service : null;
|
|
|
|
return matchedService;
|
|
|
|
});
|
2015-05-17 19:10:30 +01:00
|
|
|
|
2015-01-06 12:58:57 +00:00
|
|
|
if (matchedService) {
|
|
|
|
return matchedService.parseUrl(url).timeout(10000).then(function(result) {
|
|
|
|
return matchedService.lookupId(result.id, result.type).then(function(item) {
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|