getUserRecentlyPlayedGames function

Future<UserRecentlyPlayedGames> getUserRecentlyPlayedGames(
  1. AuthObject authorization, {
  2. required String username,
  3. int? offset,
  4. int? count,
  5. Client? client,
})

A call to this function will retrieve a list of a target user's recently played games, via their username.

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

@param username The user for which to retrieve recently played games.

@param offset Number of entries to skip (defaults to 0).

@param count Number of entries to retrieve (defaults to 10, max 50).

@example

final recentGames = await getUserRecentlyPlayedGames(
  authorization,
  username: 'xelnia',
  offset: 0,
  count: 10,
);

@returns A list of recently played games for the user.

Implementation

Future<UserRecentlyPlayedGames> getUserRecentlyPlayedGames(
  AuthObject authorization, {
  required String username,
  int? offset,
  int? count,
  http.Client? client,
}) async {
  final params = <String, dynamic>{'u': username};

  if (offset != null) {
    params['o'] = offset;
  }
  if (count != null) {
    params['c'] = count;
  }

  final url = buildRequestUrl(
    apiBaseUrl,
    '/API_GetUserRecentlyPlayedGames.php',
    authorization,
    args: params,
  );

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

  final sanitized = serializeProperties(
    rawResponse,
    shouldCastToNumbers: [
      'GameID',
      'ConsoleID',
      'NumPossibleAchievements',
      'PossibleScore',
      'NumAchieved',
      'ScoreAchieved',
      'NumAchievedHardcore',
      'ScoreAchievedHardcore',
      'MyVote',
    ],
  ) as List<dynamic>;

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