Skip to content

Instantly share code, notes, and snippets.

@nelsonsilva
Created October 30, 2013 17:30
Show Gist options
  • Save nelsonsilva/7236698 to your computer and use it in GitHub Desktop.
Save nelsonsilva/7236698 to your computer and use it in GitHub Desktop.
Simple GH Dart repo listing app to test http imports.
import 'dart:async';
import 'dart:convert' show JSON;
import 'dart:io';
import 'http://github.com/lord-otori/ascii_tables/raw/master/lib/ascii_tables.dart';
main() {
new HttpClient()
.getUrl(Uri.parse("https://api.github.com/search/repositories?q=language:dart&sort=stars&order=desc"))
.then((req) {
req.headers.add(HttpHeaders.USER_AGENT, "dart");
return req.close();
})
.then((res) {
var completer = new Completer();
var body = new StringBuffer();
res.listen(
(data) => body.write(new String.fromCharCodes(data)),
onDone: () => completer.complete(body.toString()));
return completer.future;
})
.then((body) => JSON.decode(body)["items"] )
.then((items) =>
items.map((r) => {
"Name": r["full_name"],
"Owner": r["owner"]["login"],
"Watchers": r["watchers"].toString()}))
.then((repos) {
new AsciiTables.fromList(repos)
..displayHeader(true)
..printTable();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment