Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/arnorhs/apis into arnorhs-m…
Browse files Browse the repository at this point in the history
…aster

MERGE
  • Loading branch information
kristjanmik committed Apr 28, 2013
2 parents 94f42ea + f693fc4 commit 925eb8b
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 42 deletions.
5 changes: 4 additions & 1 deletion endpoints/bus/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
exports.setup = function(){
var request = require('request');
var h = require('../../lib/helpers.js');

exports.setup = function(server){
server.post({path: '/bus/search', version: '1.0.0'}, search);
server.post({path: '/bus/realtime', version: '1.0.0'}, realtime);
}
Expand Down
4 changes: 3 additions & 1 deletion endpoints/bus/realtime.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
exports.setup = function(){
var h = require('../../lib/helpers.js');

exports.setup = function(server){
server.post({path: '/bus/realtime', version: '1.0.0'}, realtime); //Old

server.get({path: '/bus/realtime', version: '1.0.0'}, realtime);
Expand Down
2 changes: 1 addition & 1 deletion endpoints/bus/search.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.setup = function(){
exports.setup = function(server){
//Search function is broken at this point
//server.post({path: '/bus/search', version: '1.0.0'}, search);
}
Expand Down
6 changes: 5 additions & 1 deletion endpoints/car/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
exports.setup = function(){
var request = require('request');
var $ = require('jquery');
var h = require('../../lib/helpers.js');

exports.setup = function(server){
server.post({path: '/car', version: '1.0.0'}, slash);
}

Expand Down
6 changes: 5 additions & 1 deletion endpoints/car/lookup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
exports.setup = function(){
var request = require('request');
var $ = require('jquery');
var h = require('../../lib/helpers.js');

exports.setup = function(server){
server.post({path: '/car', version: '1.0.0'}, lookup); //Old

server.get({path: '/car', version: '1.0.0'}, lookup);
Expand Down
6 changes: 5 additions & 1 deletion endpoints/company/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
exports.setup = function(){
var request = require('request');
var $ = require('jquery');
var h = require('../../lib/helpers.js');

exports.setup = function(server){
server.post({path: '/company', version: '1.0.0'}, lookup); //Old

server.get({path: '/company', version: '1.0.0'}, lookup);
Expand Down
6 changes: 5 additions & 1 deletion endpoints/currency/arion.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
exports.setup = function(){
var request = require('request');
var moment = require('moment');
var h = require('../../lib/helpers.js');

exports.setup = function(server){
server.get({path: '/currency/arion', version: '1.0.0'}, slash);
}

Expand Down
7 changes: 6 additions & 1 deletion endpoints/currency/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
exports.setup = function(){
var request = require('request');
var moment = require('moment');
var $ = require('jquery');
var h = require('../../lib/helpers.js');

exports.setup = function(server){
server.post({path: '/currency', version: '1.0.0'}, slash);
}

Expand Down
4 changes: 3 additions & 1 deletion endpoints/currency/lb.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
exports.setup = function(){
var request = require('request');

exports.setup = function(server){
server.get({path: '/currency/lb', version: '1.0.0'}, getCurrencies);
};

Expand Down
6 changes: 5 additions & 1 deletion endpoints/currency/m5.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
exports.setup = function() {
var request = require('request');
var $ = require('jquery');
var h = require('../../lib/helpers.js');

exports.setup = function(server) {
server.get({path: '/currency/m5', version: '1.0.0'}, getCurrencies);
};

Expand Down
6 changes: 5 additions & 1 deletion endpoints/domainlookup/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
var request = require('request');
var $ = require('jquery');
var h = require('../../lib/helpers.js');

//Possible endpoint:
//https://www.isnic.is/is/whois/mini.php?type=all&query=apis.is
exports.setup = function(){
exports.setup = function(server){
server.get({path: '/whois', version: '1.0.0'}, slash);
}

Expand Down
6 changes: 5 additions & 1 deletion endpoints/flight/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
exports.setup = function(){
var request = require('request');
var $ = require('jquery');
var h = require('../../lib/helpers.js');

exports.setup = function(server){
server.post({path: '/flight', version: '1.0.0'}, slash); //Old

server.post({path: '/flight', version: '1.0.0'}, slash);
Expand Down
2 changes: 1 addition & 1 deletion endpoints/frontpage/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.setup = function(){
exports.setup = function(server){
server.get({path: '/'}, getSlash);
server.post({path: '/'}, postSlash);
}
Expand Down
5 changes: 4 additions & 1 deletion endpoints/house/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//Incomplete

exports.setup = function(){
var request = require('request');
var $ = require('jquery');

exports.setup = function(server){
server.get({path: '/house', version: '1.0.0'}, slash);
}

Expand Down
2 changes: 1 addition & 1 deletion endpoints/static_endpoints/frontpage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.setup = function(){
exports.setup = function(server){
server.get({path: '/'}, getFrontpage);
server.post({path: '/'}, postFrontpage);
}
Expand Down
2 changes: 1 addition & 1 deletion endpoints/static_endpoints/help_out.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.setup = function(){
exports.setup = function(server){
server.post({path: '/help_out', version: '1.0.0'}, helpOut);
server.get({path: '/help_out', version: '1.0.0'}, helpOut);
server.post({path: '/help', version: '1.0.0'}, helpOut);
Expand Down
4 changes: 2 additions & 2 deletions endpoints/static_endpoints/phone.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ var phone = function(req, res, next){
return next();
}

exports.setup = function(){
exports.setup = function(server){
server.post({path: '/phone', version: '1.0.0'}, phone);
server.get({path: '/phone', version: '1.0.0'}, phone);
server.post({path: '/phone', version: '2.0.0'}, phone);
server.get({path: '/phone', version: '2.0.0'}, phone);
}
}
6 changes: 5 additions & 1 deletion endpoints/word/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
var request = require('request');
var $ = require('jquery');
var h = require('../../lib/helpers.js');

//Very incomplete
exports.setup = function(){
exports.setup = function(server){
server.post({path: '/word', version: '1.0.0'}, slash);
}

Expand Down
8 changes: 5 additions & 3 deletions lib/endpoints.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
var fileModule = require('file');
/**
* Loads upp all the required endpoints
*/
exports.load = function(){

exports.load = function(server){
//Load all endpoints in the endpoints folder
//walk is blocking on purpose because the server can't listen yet
fileModule.walk('./endpoints', function(a, dirPath, dirs, files){
if(files){
files.forEach(function(file,key){
//Setup the endpoint via the setup function
require('../'+file).setup();
require('../'+file).setup(server);
});
}else{
console.log('There is no endpoint to load!');
}
});
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
],
"dependencies" : {
"restify": "1.4.x",
"restify": "2.4.x",
"request": "2.11.x",
"jquery": "1.8.x",
"scraper" : "0.0.9",
Expand Down
22 changes: 3 additions & 19 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
/**
* Global npm modules
*/
exports.restify = restify = require('restify');
exports.server = server = restify.createServer();

exports.scraper = scraper = require('scraper');
exports.request = request = require('request');
exports.fs = fs = require('fs');
exports.$ = $ = require('jquery');
exports.moment = moment = require('moment');
exports.file = fileModule = require('file');
exports.parseString = parseString = require('xml2js').parseString;
exports.cheerio = cheerio = require("cheerio");
exports.isn2wgs = isn2wgs = require('isn2wgs');

/**
* Global helpers
*/
exports.h = h = require('./lib/helpers.js');
exports.endpoints = endpoints = require('./lib/endpoints.js');
var restify = require('restify'),
server = restify.createServer();

//Enables the use of posted params
server.use(restify.bodyParser({ mapParams: true }));
Expand All @@ -27,7 +11,7 @@ server.use(restify.queryParser());
/**
* Endpoints setup
*/
endpoints.load();
require('./lib/endpoints.js').load(server);

/**
* Start the server
Expand Down

0 comments on commit 925eb8b

Please sign in to comment.