getTicketData function

Future getTicketData(
  1. AuthObject authorization, {
  2. int? ticketId,
  3. int? offset,
  4. int? count,
  5. bool? isGettingMostTicketedGames,
  6. String? username,
  7. int? gameId,
  8. bool? isGettingTicketsForUnofficialAchievements,
  9. bool? shouldReturnTicketsList,
  10. int? achievementId,
  11. Client? client,
})

A call to this function will retrieve ticket metadata information depending on the arguments provided.

If ticketId is provided, returns TicketEntity. If isGettingMostTicketedGames is true, returns MostTicketedGames. If username is provided, returns UserTicketStats. If gameId is provided, returns GameTicketStats. If achievementId is provided, returns AchievementTicketStats. If none of the above are provided, returns RecentTickets.

Implementation

Future<dynamic> getTicketData(
  AuthObject authorization, {
  int? ticketId,
  int? offset,
  int? count,
  bool? isGettingMostTicketedGames,
  String? username,
  int? gameId,
  bool? isGettingTicketsForUnofficialAchievements,
  bool? shouldReturnTicketsList,
  int? achievementId,
  http.Client? client,
}) async {
  final queryParams = <String, dynamic>{};

  if (ticketId != null) {
    queryParams['i'] = ticketId;
  } else if (isGettingMostTicketedGames == true) {
    queryParams['f'] = '1';
    if (count != null) queryParams['c'] = count;
    if (offset != null) queryParams['o'] = offset;
  } else if (username != null) {
    queryParams['u'] = username;
  } else if (gameId != null) {
    queryParams['g'] = gameId;
    if (isGettingTicketsForUnofficialAchievements == true) {
      queryParams['f'] = '5';
    }
    if (shouldReturnTicketsList == true) {
      queryParams['d'] = '1';
    }
  } else if (achievementId != null) {
    queryParams['a'] = achievementId;
  } else {
    if (count != null) queryParams['c'] = count;
    if (offset != null) queryParams['o'] = offset;
  }

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

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

  final sanitized = serializeProperties(
    rawResponse,
    shouldCastToNumbers: [
      'ID',
      'AchievementID',
      'Points',
      'GameID',
      'ReportType',
      'ReportState',
      'OpenTickets',
    ],
    shouldMapToBooleans: ['Hardcore'],
  ) as Map<String, dynamic>;

  if (ticketId != null) {
    return TicketEntity.fromJson(sanitized);
  } else if (isGettingMostTicketedGames == true) {
    return MostTicketedGames.fromJson(sanitized);
  } else if (username != null) {
    return UserTicketStats.fromJson(sanitized);
  } else if (gameId != null) {
    return GameTicketStats.fromJson(sanitized);
  } else if (achievementId != null) {
    return AchievementTicketStats.fromJson(sanitized);
  } else {
    return RecentTickets.fromJson(sanitized);
  }
}