Skip to content

Instantly share code, notes, and snippets.

@s3u
Created June 11, 2012 15:10
Show Gist options
  • Save s3u/2910565 to your computer and use it in GitHub Desktop.
Save s3u/2910565 to your computer and use it in GitHub Desktop.
<div id="events">
</div>
<script type="text/javascript">
uri = 'ws://ql.io';
var wsCtor = window['MozWebSocket'] ? MozWebSocket : WebSocket;
var socket = new wsCtor(uri, 'ql.io-console');
socket.onopen = function () {
var div = document.getElementById('events');
socket.onmessage = function(e) {
var text = document.createTextNode(JSON.stringify(e.data));
var p = document.createElement('p');
p.appendChild(text);
div.appendChild(p);
};
var events = ['prodid', 'details', 'reviews'];
var packet = {
type: 'events',
data: JSON.stringify(events)
};
socket.send(JSON.stringify(packet));
var packet = {
type: 'script',
data: "prodid = select ProductID[0].Value from eBay.FindProducts where\n\
QueryKeywords = 'macbook pro';\n\
details = select * from eBay.ProductDetails where\n\
ProductID in ('{prodid}') and ProductType = 'Reference';\n\
reviews = select * from eBay.ProductReviews where\n\
ProductID in ('{prodid}') and ProductType = 'Reference';\n\
return select d.ProductID[0].Value as id, d.Title as title,\n\
d.ReviewCount as reviewCount, r.ReviewDetails.AverageRating as rating\n\
from details as d, reviews as r\n\
where d.ProductID[0].Value = r.ProductID.Value;"
};
socket.send(JSON.stringify(packet));
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment