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.common_core,
      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) {
    if (item.value["templateId"].toString().startsWith("Currency:Mtx")) {
      items.add(
        MtxItem(
          client,
          id: item.key,
          profileId: profileId,
          templateId: item.value["templateId"],
          attributes: item.value["attributes"],
          quantity: item.value["quantity"],
        ),
      );
    } else {
      items.add(
        ProfileItem(
          client,
          id: item.key,
          profileId: profileId,
          templateId: item.value["templateId"],
          attributes: item.value["attributes"],
          quantity: item.value["quantity"],
        ),
      );
    }
  }

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