allow for the key to be passed as a parameter
this will also use the property `key` on the prototype if it's defined.
This commit is contained in:
parent
e4b27db043
commit
b6ad36a075
1 changed files with 9 additions and 11 deletions
20
index.js
20
index.js
|
@ -1,6 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var https = require('https');
|
const https = require('https');
|
||||||
|
const qs = require('querystring');
|
||||||
|
|
||||||
var HolidayAPI = function (key) {
|
var HolidayAPI = function (key) {
|
||||||
if ('undefined' !== typeof key) {
|
if ('undefined' !== typeof key) {
|
||||||
|
@ -11,16 +12,13 @@ var HolidayAPI = function (key) {
|
||||||
HolidayAPI.prototype.v1 = {};
|
HolidayAPI.prototype.v1 = {};
|
||||||
|
|
||||||
HolidayAPI.prototype.v1.holidays = function (parameters, callback) {
|
HolidayAPI.prototype.v1.holidays = function (parameters, callback) {
|
||||||
var url = 'https://holidayapi.com/v1/holidays';
|
const querystringObject = Object.assign(
|
||||||
var querystring = '?key=' + HolidayAPI.prototype.key;
|
{},
|
||||||
|
{key: HolidayAPI.prototype.key},
|
||||||
if ('object' === typeof parameters) {
|
parameters,
|
||||||
for (var parameter in parameters) {
|
)
|
||||||
querystring += '&' + parameter + '=' + parameters[parameter];
|
const querystring = qs.stringify(querystringObject);
|
||||||
}
|
const url = `https://holidayapi.com/v1/holidays?${querystring}`;
|
||||||
}
|
|
||||||
|
|
||||||
url += querystring;
|
|
||||||
|
|
||||||
https.get(url, function (res) {
|
https.get(url, function (res) {
|
||||||
res.on('data', function (data) {
|
res.on('data', function (data) {
|
||||||
|
|
Reference in a new issue