getInfo method

Future<Identity> getInfo()

Returns information about the institute such as the Institute.name and the Institute.url.

Implementation

Future<Identity> getInfo() async {
  Iterable<XmlElement> nodes;
  XmlElement node;
  final response = await _client.post(
    Uri.https(
      'eclass.$instituteId.gr',
      '/modules/mobile/midentity.php',
    ),
    body: {
      'token': _token ?? '',
    },
  );
  if (response.statusCode != 200) {
    throw Exception('Failed to get info.');
  }
  final decodedResponse = XmlDocument.parse(response.body);
  nodes = decodedResponse.findAllElements('institute');
  node = nodes.first;
  final institute = Institute(
    name: node.attributes[0].value,
    url: node.attributes[1].value,
  );
  nodes = decodedResponse.findAllElements('platform');
  node = nodes.first;
  final platform = Platform(
    name: node.attributes[0].value,
    version: node.attributes[1].value,
  );
  nodes = decodedResponse.findAllElements('administrator');
  node = nodes.first;
  final administrator = Administrator(
    name: node.attributes[0].value,
  );
  return Identity(
    institute: institute,
    platform: platform,
    administrator: administrator,
  );
}