updateObject method

Future<void> updateObject({
  1. required BotObject object,
})

Update an object of this bot.

  • {object} is the updated version of the object that you want to update (object's id must not be changed).

Implementation

Future<void> updateObject({
  required BotObject object,
}) async {
  try {
    if (object.id == null) {
      GetIt.I<BotnoiClient>().finishedFailed();
      GetIt.I<BotnoiClient>()
          .error
          .add("[updateObject] : this object has no id");
      return;
    }
    object.belongToBot(_bot);
    Uri url = Uri.parse(
        "${GetIt.I<BotnoiClient>().endpoint}/developer/platform-api/object/${object.objectType.stringType}");
    http.Response response = await http.put(
      url,
      headers: _getHeader,
      body: jsonEncode(object.toJson()),
    );
    if (response.statusCode == 200 ||
        response.statusCode == 204 ||
        response.statusCode == 201) {
      GetIt.I<BotnoiClient>().finishedSuccessfully();
      return;
    }
    GetIt.I<BotnoiClient>().finishedFailed();
    GetIt.I<BotnoiClient>()
        .error
        .add("[updateObject] : ${response.reasonPhrase ?? "ERROR"}");
  } catch (e) {
    GetIt.I<BotnoiClient>().finishedFailed();
    GetIt.I<BotnoiClient>().error.add("[updateObject] : $e");
  }
}