Skip to content

Instantly share code, notes, and snippets.

@mplacona
Created April 26, 2014 22:18
Show Gist options
  • Save mplacona/11332667 to your computer and use it in GitHub Desktop.
Save mplacona/11332667 to your computer and use it in GitHub Desktop.
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'dart:io';
class Gists{
// instance variable for user
String user;
getGistsForUser(String user){
this.user = user;
var url = "https://api.github.com/users/${this.user}/gists";
http.get(url)
.then(_processResults)
.catchError(_handleError);
}
_processResults(http.Response jsonString){
List<String> urls = JSON.decode(jsonString.body);
urls.forEach((element){
print(element["html_url"]);
});
}
_handleError(Error error){
print("User ${this.user} not available");
}
}
void main() {
Gists gists = new Gists();
stdout.writeln('Enter your GitHub username');
String username = stdin.readLineSync();
gists.getGistsForUser(username);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment