getRewards method

  1. @override
Future<GetRewardsOutcome> getRewards()
override

The getRewards response: { chances, campaigns, rewards, widget }. Identity travels in the headers; the body stays an empty object. Never throws: a failure is returned for the caller to report as game_rewards_failed.

Implementation

@override
Future<GetRewardsOutcome> getRewards() async {
  final client = _client();
  if (client == null) {
    return const GetRewardsFailure(GameOutcomeFailure.transport);
  }
  final post = await _post(
      client,
      DigiaEndpoints.gamificationGetRewards,
      const <String, Object?>{},
      const {'Content-Type': 'application/json'},
      'rewards');
  final response = post.response;
  if (response == null) {
    return GetRewardsFailure(GameOutcomeFailure.transport,
        timedOut: post.timedOut);
  }
  if (!response.isSuccessful) {
    return GetRewardsFailure(GameOutcomeFailure.httpStatus,
        statusCode: response.statusCode);
  }
  final payload = _responseBody(response.body, 'rewards');
  if (payload == null) {
    return GetRewardsFailure(GameOutcomeFailure.invalidResponse,
        statusCode: response.statusCode);
  }
  return GetRewardsSuccess(payload);
}