const Gtk  = imports.gi.Gtk;
const Http = imports.gi.Soup;
const Gio  = imports.gi.Gio;
const GLib = imports.gi.GLib;

Gtk.init (null, null);
var session = new Http.SessionAsync ();

function do_image_fininshed (cmsg, entry)
{
	
	var picture = new Gio.MemoryInputStream.from_data (cmsg.response_body.data, cmsg.response_body.length, null);
	return;
}

function do_finished (cmsg)
{
	var response = JSON.parse (cmsg.response_body.data);

	for (var image in response)
	{
		entry = {id:    response[image].id,
		         text:  response[image].text,
		         name:  response[image].user.name,
		         image: response[image].user.profile_image_url};
		var msg = new Http.Message.c_new ("GET", entry.image);
		session.queue_message (msg, null, null);
		msg.signal.finished.connect (do_image_fininshed, entry);
	}
	return;
}

function main ()
{
	var win = new Gtk.Window ({title: "Image Search"});
	win.show_all ();
	win.signal.destroy.connect (Gtk.main_quit);

	var msg = new Http.Message.c_new ("GET", "http://api.twitter.com/1/statuses/public_timeline.json");
	session.queue_message (msg, null, null);
	msg.signal.finished.connect (do_finished);

	Gtk.main ();
}

main ();
