update method

Future<void> update({
  1. String? label,
  2. String? avatar,
  3. String? reason,
})

Updates multiple properties of this in a single request.

When you need to update more than 2 fields, we advise you to use this method to reduce the number of outgoing requests.

Example :

await webhook.update(label: 'My webhook name', avatar: 'assets/images/my_picture.png');

Implementation

Future<void> update ({ String? label, String? avatar, String? reason }) async {
  String? path = avatar != null
    ?  await Helper.getPicture(avatar)
    : this.label;

  Response response = await ioc.use<DiscordApiHttpService>().patch(url: "/webhooks/$id")
    .payload({ 'label': label ?? this.label, 'avatar': path })
    .auditLog(reason)
    .build();

  if (response.statusCode == 200) {
    if (label != null) _label = label;
    if (avatar != null) _avatar = path;
  }
}