Skip to content

Instantly share code, notes, and snippets.

@nbqx
Created June 27, 2011 10:10
Show Gist options
  • Save nbqx/1048619 to your computer and use it in GitHub Desktop.
Save nbqx/1048619 to your computer and use it in GitHub Desktop.
var util = require('util');
var events = require('events');
var request = require('request'); //https://github.com/mikeal/request
var Wordnet = function(words){
this.ret = [];
this.words = words;
this.url = "http://nymnym.heroku.com/word/";
events.EventEmitter.call(this);
};
util.inherits(Wordnet,events.EventEmitter);
Wordnet.prototype.start = function(){
var self = this;
self.words.forEach(function(w,i){
request({uri:self.url+encodeURI(w)},function(err,res,dt){
if(err&&res.statuCode!=200) throw err;
var obj = JSON.parse(dt);
self.ret.push(obj);
if(self.ret.length==self.words.length){
self.emit('complete', self.ret);
}
});
});
}
var wds = ["苺","豆乳","アイアンメイデン","FTP","道具","コンパイラ"];
var wn = new Wordnet(wds);
wn.on('complete',function(data){
console.log(data);
});
wn.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment