Skip to content

Commit 7080550

Browse files
Merge pull request #61 from rosette-api/RCB-492_url_parameters
Rcb 492 url parameters
2 parents b0e1fe6 + c24d887 commit 7080550

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

lib/parameters.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ var http = require("http");
2323
var https = require("https");
2424
var zlib = require("zlib");
2525

26+
var querystring = require('querystring');
27+
2628
/**
2729
* Compatible server version.
2830
*
@@ -73,6 +75,9 @@ function parameters() {
7375
//headers
7476
this.customHeaders = null;
7577

78+
//URL parameters
79+
this.urlParameters = null;
80+
7681
}
7782

7883
/**
@@ -99,7 +104,8 @@ parameters.prototype.loadParams = function() {
99104
"options": this.options,
100105
"explain": this.explain,
101106
"short-string": this.shortString,
102-
"_customHeaders": this.customHeaders
107+
"_customHeaders": this.customHeaders,
108+
"_urlParameters": this.urlParameters
103109
};
104110

105111
for (var key in paramJSON) {
@@ -152,11 +158,23 @@ parameters.prototype.loadFile = function(filePath, loadedParameters, userKey, pr
152158
}
153159
headers["X-RosetteAPI-Key"] = userKey;
154160

161+
if (parameters.customHeaders != null) {
162+
parameters.customHeaders.forEach(function(element, index) {
163+
headers[element[0]] = element[1];
164+
});
165+
}
166+
167+
var path = urlParts.path;
168+
169+
if (parameters.urlParameters != null) {
170+
path = path + '?' + querystring.stringify(parameters.urlParameters);
171+
}
172+
155173
var result = new Buffer("");
156174

157175
var options = {
158176
hostname: urlParts.hostname,
159-
path: urlParts.path,
177+
path: path,
160178
method: 'POST',
161179
headers: headers,
162180
agent: false

lib/rosetteRequest.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ var zlib = require("zlib");
2121
var rosetteConstants = require("./rosetteConstants");
2222
var RosetteException = require("./rosetteExceptions");
2323

24+
var querystring = require('querystring');
25+
2426
/**
2527
* Compatible server version.
2628
*
@@ -69,9 +71,15 @@ rosetteRequest.prototype.makeRequest = function(requestType, userKey, protocol,
6971

7072
}
7173

74+
var path = urlParts.path;
75+
76+
if (parameters.urlParameters != null) {
77+
path = path + '?' + querystring.stringify(parameters.urlParameters);
78+
}
79+
7280
var options = {
7381
hostname: urlParts.hostname,
74-
path: urlParts.path,
82+
path: path,
7583
method: requestType,
7684
headers: headers,
7785
agent: false

0 commit comments

Comments
 (0)