getUserCompletedGames function

Future<UserCompletedGames> getUserCompletedGames(
  1. AuthObject authorization, {
  2. required String username,
  3. Client? client,
})

A call to this function will retrieve completion metadata about the games a given user has played.

@param authorization An object containing your username and webApiKey. This can be constructed with buildAuthorization().

@param username The user for which to retrieve completed games.

@example

final completedGames = await getUserCompletedGames(
  authorization,
  username: 'xelnia',
);

@returns An array containing completion metadata objects for a given user.

Implementation

Future<UserCompletedGames> getUserCompletedGames(
  AuthObject authorization, {
  required String username,
  http.Client? client,
}) async {
  final url = buildRequestUrl(
    apiBaseUrl,
    '/API_GetUserCompletedGames.php',
    authorization,
    args: {'u': username},
  );

  final rawResponse = await call(url: url, client: client);

  final sanitized = serializeProperties(
    rawResponse,
    shouldCastToNumbers: [
      'GameID',
      'ConsoleID',
      'MaxPossible',
      'NumAwarded',
      'PctWon',
    ],
    shouldMapToBooleans: ['HardcoreMode'],
  ) as List<dynamic>;

  return sanitized
      .map((dynamic item) =>
          UserCompletedGame.fromJson(item as Map<String, dynamic>))
      .toList();
}