From 3e5ebc888a7857b242440cc6a395fcb741e99a1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o-Paul=20COUTURIER?= Date: Mon, 24 Mar 2014 08:56:38 +0100 Subject: [PATCH 1/2] Add an options argument to query --- index.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 11bc838..d782879 100644 --- a/index.js +++ b/index.js @@ -5,12 +5,22 @@ var Client = exports.Client = function Client(appKey) { this.appKey = appKey } -Client.prototype.query = function(input, cb) { +Client.prototype.query = function(input, options, cb) { if(!this.appKey) { return cb("Application key not set", null) } - - var uri = 'http://api.wolframalpha.com/v2/query?input=' + encodeURIComponent(input) + '&primary=true&appid=' + this.appKey + + if(typeof options === 'function') { + cb = options; + options = {primary: true}; + } + + var query = ''; + for(var i in options) { + query += '&' + i + '=' + options[i]; + } + + var uri = 'http://api.wolframalpha.com/v2/query?input=' + encodeURIComponent(input) + query + '&appid=' + this.appKey request(uri, function(error, response, body) { if(!error && response.statusCode == 200) { From 4f0f71183b0d3ca08115e28bd1c245ed61e1dc51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o-Paul=20COUTURIER?= Date: Tue, 10 Jun 2014 10:49:02 +0200 Subject: [PATCH 2/2] Add URI encoding for options --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index d782879..d0cd557 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,7 @@ Client.prototype.query = function(input, options, cb) { var query = ''; for(var i in options) { - query += '&' + i + '=' + options[i]; + query += '&' + i + '=' + encodeURIComponent(options[i]); } var uri = 'http://api.wolframalpha.com/v2/query?input=' + encodeURIComponent(input) + query + '&appid=' + this.appKey