init method

Future init()

init the profile

Implementation

Future<dynamic> init() async {
  if (initialized == true) return;

  var res = await client.send(
    method: "POST",
    url: MCP(
      FortniteProfile.athena,
      accountId: client.accountId,
    ).QueryProfile,
    body: {},
  );

  created = DateTime.parse(res["profileChanges"][0]["profile"]["created"]);
  updated = DateTime.parse(res["profileChanges"][0]["profile"]["updated"]);
  serverTime = DateTime.parse(res["serverTime"]);
  rvn = res["profileChanges"][0]["profile"]["rvn"];
  Map<String, dynamic> _items = res["profileChanges"][0]["profile"]["items"];
  stats = res["profileChanges"][0]["profile"]["stats"]["attributes"];

  for (var item in _items.entries) {
    switch (item.value["templateId"].toString().split(":")[0]) {
      case "Quest":
        items.add(
          QuestItem(
            client,
            id: item.key,
            profileId: profileId,
            templateId: item.value["templateId"],
            attributes: item.value["attributes"],
            quantity: item.value["quantity"],
          ),
        );
        break;

      case "AthenaCharacter":
      case "AthenaBackpack":
      case "AthenaPickaxe":
      case "AthenaGlider":
      case "AthenaSkyDiveContrail":
      case "AthenaDance":
      case "AthenaItemWrap":
      case "AthenaMusicPack":
      case "AthenaLoadingScreen":
        items.add(
          AthenaCosmetic(
            client,
            id: item.key,
            profileId: profileId,
            templateId: item.value["templateId"],
            attributes: item.value["attributes"],
            quantity: item.value["quantity"],
          ),
        );
        break;

      case "CosmeticLocker":
        items.add(
          CosmeticLocker(
            client,
            id: item.key,
            profileId: profileId,
            templateId: item.value["templateId"],
            attributes: item.value["attributes"],
            quantity: item.value["quantity"],
          ),
        );
        break;

      default:
        items.add(
          ProfileItem(
            client,
            id: item.key,
            profileId: profileId,
            templateId: item.value["templateId"],
            attributes: item.value["attributes"],
            quantity: item.value["quantity"],
          ),
        );
        break;
    }
  }

  initialized = true;
  client.log(LogLevel.info,
      "Athena profile module initialized [${client.accountId}]");
}