Created
January 26, 2015 19:42
-
-
Save szilardhuber/e1ef871bd7023b095297 to your computer and use it in GitHub Desktop.
Virtdb - query Github repositories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var DataProvider = require("virtdb-provider"); | |
var virtdb = new DataProvider('github-repository-provider', 'tcp://192.168.221.11:12345'); | |
var https = require('https'); | |
virtdb.onMetaDataRequest( function(request) { | |
var table = virtdb.createTable('repositories'); | |
table.addField('html_url', 'STRING'); | |
table.addField('name', 'STRING'); | |
table.addField('size', 'UINT32'); | |
table.addField('watchers_count', 'UINT32'); | |
table.addField('description', 'STRING'); | |
virtdb.sendMetaData(table); | |
}); | |
virtdb.onQuery(function(query) { | |
var options = { | |
host: 'api.github.com', | |
path: '/users/starschema/repos', | |
method: 'GET', | |
headers: { | |
'Content-Type': 'application/json', | |
'User-Agent': 'Awesome-Octocat-App' | |
} | |
}; | |
https.get(options, function(resp){ | |
var responseString = ''; | |
resp.on('data', function(chunk){ | |
responseString += chunk; | |
}); | |
resp.on("error", function(e){ | |
console.log("Got error: " + e.message); | |
}); | |
resp.on('end', function() { | |
var reply = virtdb.createReply(query); | |
var responseObject = JSON.parse(responseString); | |
for (var i = 0; i < responseObject.length; i++) | |
{ | |
reply.pushObject(responseObject[i]); | |
} | |
virtdb.send(reply); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment