registerPlayerAction function

Future<List<PlayerAchievement>> registerPlayerAction(
  1. String playerToken,
  2. String playerUid,
  3. String action,
  4. String value,
  5. Config config,
)

Implementation

Future<List<PlayerAchievement>> registerPlayerAction(String playerToken,
    String playerUid, String action, String value, Config config) async {
  final response = await http.post(
      Uri.parse(
          '${config.server}/api/tenant/${config.operatorId}/register-player-action/$playerUid/$action'),
      headers: <String, String>{
        'Content-Type': 'application/json; charset=UTF-8',
      },
      body: jsonEncode(<String, String>{
        "operator_id": config.operatorId,
        "client_secret": config.clientSecret,
        "client_id": config.clientId,
        "player_id": playerUid,
        "token": playerToken,
        "value": value
      }));

  if (response.statusCode == 200) {
    // If the server did return a 200 OK response,
    // then parse the JSON.
    var rb = response.body;

    // store json data into list
    var list = json.decode(rb);
    List<PlayerAchievement> achievements = [];

    achievements = list == null
        ? achievements
        : list
            .map<PlayerAchievement>((i) => PlayerAchievement.fromJson(i))
            .toList();
    // iterate over the list and map each object in list to Img by calling Img.fromJson
    // Auth auth = new Auth(token: rb);
    return achievements;
  } else {
    // If the server did not return a 200 OK response,
    // then throw an exception.
    throw Exception('Failed to notify Player Action');
  }
}