Created
April 26, 2014 22:18
-
-
Save mplacona/11332667 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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