Skip to content

Commit

Permalink
Merge pull request #13 from PrimaxLite/develop
Browse files Browse the repository at this point in the history
Merged develope branch to v0.2 release
  • Loading branch information
TheEskhaton committed Nov 5, 2013
2 parents 5f0f53d + 349ca4b commit 45c59e3
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 14 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: node_js
6 changes: 2 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
var tecaj = require('./tecaj.js');
tecaj.getTecaj(process.argv[2], function(result) {
console.log('THIS IS A RESULT: ' + JSON.stringify(result));
});
var tecaj = require('./lib/tecaj.js');
module.exports = tecaj;
27 changes: 20 additions & 7 deletions tecaj.js → lib/tecaj.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
var logger = require('winston'),
var winston = require('winston'),
logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({ level: 'error' })
]
}),
request = require("request"),
usedDate = '',
d = new Date(),
helpers = require('./lib/helpers'),
helpers = require('./helpers'),
/* Variable that, when set, represent a function
that will be called when tecaj.js successfully receives JSON */
resultCallback,
Expand Down Expand Up @@ -37,9 +42,17 @@ var logger = require('winston'),
}
}

module.exports = { getTecaj : function(date, results) {
resultCallback = results;
usedDate = date || dateString(d);
var link = "http://www.hnb.hr/tecajn/f" + usedDate + ".dat";
request(link, callback); }
module.exports = {
getTecaj : function(date, results) {
if(typeof date === 'function'){
resultCallback = date;
usedDate = dateString(d);
}
else{
resultCallback = results;
usedDate = date || dateString(d);
}
var link = "http://www.hnb.hr/tecajn/f" + usedDate + ".dat";
request(link, callback);
}
}
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
"bugs": {
"url": "https://github.com/PrimaxLite/hnb_script/issues"
},
"main": "tecaj.js",
"devDependencies": {},
"main": "index.js",
"devDependencies": {
"should": "~2.0.2",
"mocha": "~1.14.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha -R spec ./test/tests.js"
},
"keywords": [
"hnb",
Expand Down
20 changes: 20 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var should = require('should');
var tecaj = require('../index');

describe('tecaj', function(){
it('should have a getTecaj method', function(){
tecaj.should.have.property('getTecaj').with.type('function');
});
it('should return a value when called with 2 parameters', function(done){
tecaj.getTecaj(null, function(t){
should.exist(t);
done();
});
});
it('should return a value when called with just a callback', function(done){
tecaj.getTecaj(function(t){
should.exist(t);
done();
});
});
});

0 comments on commit 45c59e3

Please sign in to comment.