reserveName function

Future<bool> reserveName(
  1. String newName,
  2. AccessToken accessToken
)

Reserves the newName for this Mojang Account.

Implementation

// TODO: Improved return type including error message. Or just throw an error?
Future<bool> reserveName(String newName, AccessToken accessToken) async {
  final headers = {
    'authorization': 'Bearer $accessToken',
    'Origin': 'https://checkout.minecraft.net',
  };
  final response = await requestBody(
      http.put, _mojangApi, 'user/profile/agent/minecraft/name/$newName', {},
      headers: headers);
  if (response.statusCode != 204) {
    return false;
    /* switch (response.statusCode) {
        case 400: throw Exception('Name is unavailable.');
        case 401: throw Exception('Unauthorized.');
        case 403: throw Exception('Forbidden.');
        case 504: throw Exception('Timed out.');
        default: throw Exception('Unexpected error occurred.');
      } */
  } else {
    return true;
  }
}