eh-api-client
Advanced tools
Comparing version 0.7.3 to 0.7.4
20
index.js
@@ -15,2 +15,16 @@ var | ||
function _url(data) { | ||
if(typeof data === "string") { | ||
return data; | ||
} | ||
if(data instanceof Array) { | ||
var url = data.shift(); | ||
url = url.replace(/\?\?/g, function() { | ||
return encodeURIComponent(data.shift()); | ||
}); | ||
return url; | ||
} | ||
throw new Error("url should be a string or an array"); | ||
} | ||
var methods = [ | ||
@@ -34,3 +48,3 @@ "GET", | ||
Client.prototype.fork = function(subUrl) { | ||
apiURL = this.apiURL + subUrl; | ||
apiURL = this.apiURL + _url(subUrl); | ||
var newClient = new Client(apiURL, this._options); | ||
@@ -45,3 +59,3 @@ return newClient; | ||
} | ||
if(typeof options === "string") { | ||
if(typeof options === "string" || (options instanceof Array)) { | ||
options = { | ||
@@ -58,3 +72,3 @@ url: options | ||
var reqParams = { | ||
url: this.apiURL + options.url, | ||
url: this.apiURL + _url(options.url), | ||
method: method, | ||
@@ -61,0 +75,0 @@ json: true, |
{ | ||
"name": "eh-api-client", | ||
"version": "0.7.3", | ||
"version": "0.7.4", | ||
"description": "Node.js rest client", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,2 +8,3 @@ var | ||
var client = f.getClient(1, "web"); | ||
var enc = encodeURIComponent; | ||
@@ -79,2 +80,17 @@ describe("Internal Auth Client test", function() { | ||
}); | ||
it("should fork client with placeholders in URL", function() { | ||
var fork = client.fork(["/blabla/??/??", "///&%&*", "&&*^$$$!@$//?"]); | ||
fork.apiURL.should.equal(client.apiURL + "/blabla/" + enc("///&%&*") + "/" + enc("&&*^$$$!@$//?")); | ||
}); | ||
it("should request url with placeholders", function(done) { | ||
client.get(["/test/??/??", "///&%&*", "&&*^$$$!@$//?"], { | ||
test: true | ||
}, function(err, req) { | ||
should.not.exists(err); | ||
req.url.should.equal("http://localhost:3000/test/" + enc("///&%&*") + "/" + enc("&&*^$$$!@$//?")); | ||
done(); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9376
338