deleteItem method

  1. @override
Future<Map<String, String>> deleteItem(
  1. GlpiItemType itemType,
  2. int id, {
  3. bool forcePurge = false,
  4. bool history = true,
})
override

Return the id of the item deleted with true is the deletion is complete. forcePurge will delete the item permanently. history set to false will prevent the deletion from being added to the global history.

Implementation

@override
Future<Map<String, String>> deleteItem(GlpiItemType itemType, int id,
    {bool forcePurge = false, bool history = true}) async {
  if (sessionToken!.isEmpty) {
    throw Exception('No session token, initSession first');
  }

  final Map<String, String> headers = {
    'Session-Token': sessionToken!,
    'Content-Type': 'application/json',
    ...?appToken != null ? {'App-Token': appToken!} : null,
  };

  final uri = Uri.parse(
      '$host/${itemType.toString().split('.').last}/$id?force_purge=$forcePurge&history=$history');

  final response = await _innerClient.delete(uri, headers: headers);

  if (response.statusCode != 200 &&
      response.statusCode != 204 &&
      response.statusCode != 207) {
    throw GlpiException.fromResponse(
        response.statusCode, json.decode(response.body));
  }

  return Future.value(json.decode(response.body));
}