From 53af923fa2b67c288798bba229a57706d9e53488 Mon Sep 17 00:00:00 2001 From: "Mark A. Yoder" Date: Mon, 1 Dec 2014 20:37:55 -0500 Subject: [PATCH 1/2] Added ability to pass options --- index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 11bc838..7125699 100644 --- a/index.js +++ b/index.js @@ -9,8 +9,19 @@ Client.prototype.query = function(input, cb) { if(!this.appKey) { return cb("Application key not set", null) } + var options; + var search; + if(typeof(input) === 'object') { + // If an ojbect is passed, look for search string and options + search = input.search; + options = input.options; + } else { + // If it's not an object, assume it's the search string + search = input; + options = ""; + } - var uri = 'http://api.wolframalpha.com/v2/query?input=' + encodeURIComponent(input) + '&primary=true&appid=' + this.appKey + var uri = 'http://api.wolframalpha.com/v2/query?input=' + encodeURIComponent(search) + '&primary=true&appid=' + this.appKey + options; request(uri, function(error, response, body) { if(!error && response.statusCode == 200) { From ca57d94bd260fd48ca9cdf3fd36fd73d49027afd Mon Sep 17 00:00:00 2001 From: "Mark A. Yoder" Date: Mon, 1 Dec 2014 20:39:34 -0500 Subject: [PATCH 2/2] Added options test --- test/option-test.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 test/option-test.js diff --git a/test/option-test.js b/test/option-test.js new file mode 100755 index 0000000..328bfb4 --- /dev/null +++ b/test/option-test.js @@ -0,0 +1,23 @@ +#!/usr/bin/env node + +console.log(process.env.WOLFRAM_APPID); + +var wolfram = require('./node-wolfram').createClient(process.env.WOLFRAM_APPID) + +wolfram.query({search: "words containing msdoep", + options: + "&podstate=WordsMadeWithOnlyLetters__Show+all" + + "&podstate=WordsMadeWithOnlyLetters__Disallow+repetition" + + "&includepodid=WordsMadeWithOnlyLetters"}, + function(err, result) { + if(err) throw err + console.log("Size: %d", result.length); + console.log("Result: %j", result[0].subpods[0].value); +}) + +wolfram.query("words containing abcdefg", + function(err, result) { + if(err) throw err + console.log("Size: %d", result.length); + console.log("Result: %j", result); +})