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