getBookmarksFromUsername method Null safety
- String username
getBookmarksFromusername searches the public bookmarks from the username in the argument.
If a work has multiple fandoms, only the first is listed.
Currently, it only searches the first page of bookmarks sorted by date of bookmark. If it fails to find a value, it will be set to "Unknown" in the case of strings or 1 in the case of ints.
Will throw error if user is not found, but not if user has 0 bookmarks.
Implementation
static Future<List<Work>> getBookmarksFromUsername(
final String username) async {
final bookmarkedWorks = <Work>[];
final resp = await http.get(
Uri.parse("https://archiveofourown.org/users/$username/bookmarks"));
if (resp.statusCode == 404) {
throw ("No user found");
}
final bookmarks = parse(resp.body).querySelectorAll("li.bookmark");
for (final bookmark in bookmarks) {
bookmarkedWorks.add(_getWork(bookmark));
}
return bookmarkedWorks;
}