Q&D wrapper
This commit is contained in:
parent
87874b013f
commit
221e1303be
2 changed files with 71 additions and 0 deletions
51
index.js
Normal file
51
index.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
'use strict';
|
||||
|
||||
var https = require('https');
|
||||
|
||||
var HolidayAPI = function (key) {
|
||||
if ('undefined' !== typeof key) {
|
||||
HolidayAPI.prototype.key = key;
|
||||
}
|
||||
};
|
||||
|
||||
HolidayAPI.prototype.v1 = {};
|
||||
|
||||
HolidayAPI.prototype.v1.holidays = function (parameters, callback) {
|
||||
var url = 'https://holidayapi.com/v1/holidays';
|
||||
var querystring = '?key=' + HolidayAPI.prototype.key;
|
||||
|
||||
if ('object' === typeof parameters) {
|
||||
for (var parameter in parameters) {
|
||||
querystring += '&' + parameter + '=' + parameters[parameter];
|
||||
}
|
||||
}
|
||||
|
||||
url += querystring;
|
||||
|
||||
https.get(url, function (res) {
|
||||
res.on('data', function (data) {
|
||||
try {
|
||||
data = JSON.parse(data);
|
||||
} catch (e) {
|
||||
data = {};
|
||||
}
|
||||
|
||||
var error = null;
|
||||
|
||||
if (res.statusCode !== 200) {
|
||||
if ('undefined' === typeof data['error']) {
|
||||
error = 'Unknown error.';
|
||||
} else {
|
||||
error = data.error;
|
||||
}
|
||||
}
|
||||
|
||||
return callback(error, data);
|
||||
});
|
||||
}).on('error', function (e) {
|
||||
callback(e.message);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = HolidayAPI;
|
||||
|
20
package.json
Normal file
20
package.json
Normal file
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"name": "node-holidayapi",
|
||||
"version": "0.0.0",
|
||||
"description": "Official Node.js library for Holiday API",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/joshtronic/node-holidayapi.git"
|
||||
},
|
||||
"keywords": [ "holiday", "holidays", "holidayapi" ],
|
||||
"author": "Josh Sherman <hello@holidayapi.com> (https://holidayapi.com)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/joshtronic/node-holidayapi/issues"
|
||||
},
|
||||
"homepage": "https://holidayapi.com"
|
||||
}
|
Reference in a new issue