wadl-client
Advanced tools
Comparing version 0.2.0-beta.1 to 0.2.0-beta.2
{ | ||
"name": "wadl-client", | ||
"main": "wadl-client.js", | ||
"version": "0.2.0-beta.1", | ||
"version": "0.2.0-beta.2", | ||
"homepage": "https://github.com/rbelouin/wadl-client", | ||
@@ -6,0 +6,0 @@ "authors": [ |
{ | ||
"name": "wadl-client", | ||
"version": "0.2.0-beta.1", | ||
"version": "0.2.0-beta.2", | ||
"description": "Generate a Javascript client for a web API providing a WADL description", | ||
@@ -5,0 +5,0 @@ "main": "wadl-client.js", |
@@ -10,3 +10,3 @@ var resources = resources || require("./resources.js"); | ||
it("should be able to download resources", function(done) { | ||
var res = client.test.static.get(); | ||
var res = client.test.static.get().send(); | ||
@@ -20,3 +20,3 @@ res.onValue(function(data) { | ||
it("should be able to download resources with query params", function(done) { | ||
var res = client.test.query.get.withQuery({a: 12345})(); | ||
var res = client.test.query.get().withQuery({a: 12345}).send(); | ||
@@ -30,3 +30,3 @@ res.onValue(function(data) { | ||
it("should be able to download resources with path params", function(done) { | ||
var res = client.test.dynamic._.get.withParams(["12345"])(); | ||
var res = client.test.dynamic._.get().withParams(["12345"]).send(); | ||
@@ -47,3 +47,3 @@ res.onValue(function(data) { | ||
var res = client.test.private.get(); | ||
var res = client.test.private.get().send(); | ||
@@ -57,5 +57,5 @@ res.onValue(function(data) { | ||
it("should be able to download resources by giving specific header at sending time", function(done) { | ||
var res = client.test.private.get.withHeaders({ | ||
var res = client.test.private.get().withHeaders({ | ||
Authorization: "12345" | ||
})(); | ||
}).send(); | ||
@@ -69,3 +69,3 @@ res.onValue(function(data) { | ||
it("should be able to upload resources", function(done) { | ||
var res = client.test.upload.post("12345"); | ||
var res = client.test.upload.post().send("12345"); | ||
@@ -79,5 +79,5 @@ res.onValue(function(data) { | ||
it("should be able to upload resources with a specific header", function(done) { | ||
var res = client.test.private.upload.put.withHeaders({ | ||
var res = client.test.private.upload.put().withHeaders({ | ||
Authorization: "12345" | ||
})("12345"); | ||
}).send("12345"); | ||
@@ -91,3 +91,3 @@ res.onValue(function(data) { | ||
it("should be able to parse JSON resources if parse setting is set to true", function(done) { | ||
var res = client.test.json.get.withParsing()(); | ||
var res = client.test.json.get().withParsing().send(); | ||
@@ -102,3 +102,3 @@ res.onValue(function(data) { | ||
it("should be able to parse JSON resources even if Content-Type header has a charset token", function(done) { | ||
var res = client.test.json2.get.withParsing()(); | ||
var res = client.test.json2.get().withParsing().send(); | ||
@@ -113,3 +113,3 @@ res.onValue(function(data) { | ||
it("should be able to parse XML resources if parse setting is set to true", function(done) { | ||
var res = client.test.xml.get.withParsing()(); | ||
var res = client.test.xml.get().withParsing().send(); | ||
@@ -131,3 +131,3 @@ res.onValue(function(data) { | ||
it("should be able to parse JSON resources if parse setting is set to true, even on error", function(done) { | ||
var res = client.test.json.fail.get.withParsing()(); | ||
var res = client.test.json.fail.get().withParsing().send(); | ||
@@ -142,3 +142,3 @@ res.onError(function(data) { | ||
it("must not fail when checking Content-Type header", function(done) { | ||
var res = client.test.json3.get.withParsing()(); | ||
var res = client.test.json3.get().withParsing().send(); | ||
@@ -145,0 +145,0 @@ res.onValue(function() { |
@@ -119,5 +119,7 @@ var WadlClient = (function() { | ||
return function() { | ||
var send = function(body) { | ||
var host = send.host; | ||
var params = Array.apply(Array, send.params); | ||
var req = {}; | ||
req.send = function(body) { | ||
var host = req.host; | ||
var params = Array.apply(Array, req.params); | ||
var path = pathTemplate.replace(/{[^}]*}/g, function(matched) { | ||
@@ -131,5 +133,5 @@ var param = params.shift(); | ||
method: verb.toUpperCase(), | ||
headers: send.headers, | ||
qs: send.query, | ||
parse: send.parse, | ||
headers: req.headers, | ||
qs: req.query, | ||
parse: req.parse, | ||
body: body | ||
@@ -139,35 +141,35 @@ }); | ||
send.host = defaultSettings.host || ""; | ||
send.withHost = function(host) { | ||
send.host = host; | ||
return send; | ||
req.host = defaultSettings.host || ""; | ||
req.withHost = function(host) { | ||
req.host = host; | ||
return req; | ||
}; | ||
send.params = []; | ||
send.withParams = function(params) { | ||
send.params = params; | ||
return send; | ||
req.params = []; | ||
req.withParams = function(params) { | ||
req.params = params; | ||
return req; | ||
}; | ||
send.headers = defaultSettings.headers || {}; | ||
send.withHeaders = function(headers) { | ||
req.headers = defaultSettings.headers || {}; | ||
req.withHeaders = function(headers) { | ||
for(var name in headers) { | ||
send.headers[name] = headers[name]; | ||
req.headers[name] = headers[name]; | ||
} | ||
return send; | ||
return req; | ||
}; | ||
send.query = {}; | ||
send.withQuery = function(query) { | ||
send.query = query; | ||
return send; | ||
req.query = {}; | ||
req.withQuery = function(query) { | ||
req.query = query; | ||
return req; | ||
}; | ||
send.parse = defaultSettings.parse; | ||
send.withParsing = function(parse) { | ||
send.parse = typeof parse == "undefined" ? true : parse; | ||
return send; | ||
req.parse = defaultSettings.parse; | ||
req.withParsing = function(parse) { | ||
req.parse = typeof parse == "undefined" ? true : parse; | ||
return req; | ||
}; | ||
return send; | ||
return req; | ||
}; | ||
@@ -203,7 +205,3 @@ }; | ||
var method = methods[i]; | ||
Object.defineProperty(node, method.verb.toLowerCase(), { | ||
get: prepareRequest(method.verb, path, settings || {}), | ||
configurable: true | ||
}); | ||
node[method.verb.toLowerCase()] = prepareRequest(method.verb, path, settings || {}); | ||
} | ||
@@ -210,0 +208,0 @@ } |
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
18039
505