From 86f076750fb1c9e8b2100dbec12f5c75bacc69df Mon Sep 17 00:00:00 2001 From: SamHausmann Date: Wed, 1 Jun 2016 11:19:28 -0400 Subject: [PATCH] fixed custom header scope issue --- examples/language.js | 4 ++++ lib/parameters.js | 8 ++++++-- lib/rosetteRequest.js | 7 +++++++ package.json | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/examples/language.js b/examples/language.js index f6c62b2..5e7b1ff 100644 --- a/examples/language.js +++ b/examples/language.js @@ -12,6 +12,10 @@ parser.addArgument(["--url"], {help: "Rosette API alt-url", required: false}); var args = parser.parseArgs(); var api = new Api(args.key, args.url); var endpoint = "language"; +var appHeader = []; +appHeader[0] = "X-RosetteAPI-App" +appHeader[1] = "app"; +api.parameters.customHeaders = [appHeader]; var content = "Por favor SeƱorita, says the man."; diff --git a/lib/parameters.js b/lib/parameters.js index 855ab3a..0467170 100644 --- a/lib/parameters.js +++ b/lib/parameters.js @@ -73,6 +73,9 @@ function parameters() { //morphology this.morphology = null; + //custom headers + this.customHeaders = null; + } /** @@ -103,11 +106,12 @@ parameters.prototype.loadParams = function() { "short-string": this.shortString, "morphology": this.morphology, "_maxRetries": this.maxRetries, - "_msInterval": this.msInterval + "_msInterval": this.msInterval, + "customHeaders": this.customHeaders }; for (var key in paramJSON) { - if (key.substring(0, 1) !== '_' && paramJSON[key] != null) { + if (key.substring(0, 1) !== '_' && paramJSON[key] != null && key != "customHeaders") { tempJSON[key] = paramJSON[key]; } } diff --git a/lib/rosetteRequest.js b/lib/rosetteRequest.js index 9ffd00d..9acb838 100644 --- a/lib/rosetteRequest.js +++ b/lib/rosetteRequest.js @@ -75,6 +75,13 @@ rosetteRequest.prototype.makeRequest = function(requestType, userKey, urlParts, headers["X-RosetteAPI-Key"] = userKey; } + if(parameters.customHeaders != null){ + parameters.customHeaders.forEach( function(element, index) { + headers[element[0]] = element[1]; + }); + + } + var options = { hostname: urlParts.hostname, path: urlParts.path, diff --git a/package.json b/package.json index 54fde41..bb4c553 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rosette-api", - "version": "1.1.3", + "version": "1.1.4", "description": "Rosette API Node.js client SDK", "main": "index", "directories": {