authenticate static method

Future<bool> authenticate()

Implementation

static Future<bool> authenticate() async {
  // try {
  var req = InterfaceLevelsAvailableRequest(hsXsdVersion: '01.01.0128', messageID: currentMessageID);
  // var req = InterfaceLevelRequest(level: "01.03", messageID: currentMessageID);

  String interfaceAvailableLevelsRes = await send(xml: req.toXML());
  InterfaceLevelsAvailableResponse res = InterfaceLevelsAvailableResponse.fromXML(interfaceAvailableLevelsRes);
  if (res.result.toLowerCase() == "ok") {
    if (!res.interfaceLevels.any((element) => element.level == "01.03")) {
      Get.snackbar("Authenticate Failed", "Interface Level 01.03 is Not Available!");
      return false;
    }
    var req = InterfaceLevelRequest(
        level: res.interfaceLevels.firstWhere((element) => element.level == "01.03").level, messageID: currentMessageID);
    String interfaceLevelRes = await send(xml: req.toXML());
    InterfaceLevelResponse ilRes = InterfaceLevelResponse.fromXML(interfaceLevelRes);

    if (ilRes.result.toLowerCase() == "ok") {
      AuthenticateRequest authReq = AuthenticateRequest(
        airline: _instance.airline,
        eventToken: _instance.evenToken!,
        platformDefinedParameter: _instance.applicationToken!,
        applications: [
          Application(applicationName: _instance.applicationName, applicationVersion: _instance.applicationVersion)
        ],
        messageID: currentMessageID,
      );

      String authResXML = await send(xml: authReq.toXML());
      AuthenticateResponse authRes = AuthenticateResponse.fromXML(authResXML);
      //remove subdevices
      authRes.deviceList.removeWhere((element) => element.deviceIndex.contains("."));
      _instance.authenticated = true;
      log("Authenticated Token: ${authRes.deviceToken}");
      log("Total Devices Found: ${authRes.deviceList.length}");
      log(authRes.deviceList.map((e) => "${e.deviceIndex} -> ${e.deviceName} ${e.deviceParameterType} \n").join());
      _instance.deviceToken = authRes.deviceToken;
      _instance.platformDevices = authRes.platformDevices;
      _instance.notifier!();
      // connectToAvailableNeededDevices();
      return true;
    } else {
      return false;
    }
  } else {
    return false;
  }
  // } catch (e) {
  //   log("Auth Exception"+e.toString());
  //   return false;
  // }
}