update method

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

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 }) async {
  Http http = ioc.singleton(Service.http);
  String? path = avatar != null
    ?  await Helper.getPicture(avatar)
    : this.label;

  Response response = await http.patch(url: "/webhooks/$id", payload: {
    'label': label ?? this.label,
    'avatar': path,
  });

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