Created
April 29, 2014 12:19
-
-
Save mplacona/11398580 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'; | |
import 'dart:async'; | |
class Gists{ | |
// instance variable for user | |
String user; | |
Future getGistsForUser(String user){ | |
this.user = user; | |
var url = "https://api.github.com/users/${this.user}/gists"; | |
return http.get(url) | |
.then((res) => _processResults(res)) | |
.catchError(_handleError); | |
} | |
_processResults(http.Response jsonString){ | |
List<String> items = JSON.decode(jsonString.body); | |
var res = []; | |
items.forEach((element) => res.add(element["html_url"])); | |
return res; | |
} | |
_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) | |
.then((res) => print(res.join("\n"))) | |
.catchError((error) => print(error.toString())); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment