Skip to content

Commit

Permalink
Rename tag
Browse files Browse the repository at this point in the history
  • Loading branch information
virtualmarc committed Feb 24, 2020
1 parent 34ba50f commit 4daba16
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- List short URL's
- List tags
- Add tags
- Rename tag

## 0.2.0

Expand Down
25 changes: 25 additions & 0 deletions lib/src/shlink_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,29 @@ class Shlink {
.map((t) => t.toString())
.toList();
}

/// Rename a tag from [oldName] to [newName]
Future<bool> renameTag(String oldName, String newName) async {
String sUrl = '$_url$_API_PATH/tags';

Map<String, dynamic> 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);
}
}

0 comments on commit 4daba16

Please sign in to comment.