deleteObject method

Future deleteObject()

Delete the object referred to by this AlgoliaObjectReference.

If no object exists yet, the update will fail.

Implementation

Future deleteObject() async {
  assert(
      _objectId != null, 'You can\'t delete an object without an objectID.');
  try {
    String url = '${algolia._host}indexes/$_index';
    if (_objectId != null) {
      url = '$url/$_objectId';
    }
    Response response = await delete(
      Uri.parse(url),
      headers: algolia._header,
    );
    Map<String, dynamic> body = json.decode(response.body);
    return AlgoliaTask._(algolia, _index, body);
  } catch (err) {
    return err;
  }
}