getUuid function
Returns the UUID for player username
.
Implementation
Future<PlayerUuid> getUuid(String username) async {
final response =
await request(http.get, _mojangApi, 'users/profiles/minecraft/$username');
if (response.body.isEmpty && response.statusCode == 204) {
throw ArgumentError.value(username, 'username', 'No user was found for given username');
}
final map = parseResponseMap(response);
if (map['error'] != null) {
if (response.statusCode == 404) {
throw ArgumentError.value(
username, 'username', 'No user was found for given username');
} else if (response.statusCode == 429) {
throw TooManyRequestsException(map['errorMessage']);
}
throw Exception(map['errorMessage']);
}
return PlayerUuid(username, map['id']);
}