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) { 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); +})