From 4daba163e69067c4cb2efc4c13f1647108e5e67b Mon Sep 17 00:00:00 2001 From: virtualmarc Date: Mon, 24 Feb 2020 22:14:09 +0100 Subject: [PATCH] Rename tag --- CHANGELOG.md | 1 + lib/src/shlink_base.dart | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b44b935..3d248d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - List short URL's - List tags - Add tags +- Rename tag ## 0.2.0 diff --git a/lib/src/shlink_base.dart b/lib/src/shlink_base.dart index 2463c5c..873b9f2 100644 --- a/lib/src/shlink_base.dart +++ b/lib/src/shlink_base.dart @@ -271,4 +271,29 @@ class Shlink { .map((t) => t.toString()) .toList(); } + + /// Rename a tag from [oldName] to [newName] + Future renameTag(String oldName, String newName) async { + String sUrl = '$_url$_API_PATH/tags'; + + Map mJson = {'oldName': oldName, 'newName': newName}; + + HttpClientRequest request = await HttpClient().putUrl(Uri.parse(sUrl)) + ..headers.contentType = ContentType.json + ..headers.set(_HEADER_API_KEY, _apiKey) + ..write(jsonEncode(mJson)); + + HttpClientResponse response = await request.close(); + + if (response.statusCode == 204) { + return true; + } + + if (response.statusCode == 404) { + return false; + } + + String sBody = await utf8.decoder.bind(response).single; + throw ShlinkException.fromJson(response.statusCode, sBody); + } }