Skip to content

Commit

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

## 0.2.0

Expand Down
38 changes: 38 additions & 0 deletions lib/src/shlink_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,42 @@ class Shlink {
String sBody = await utf8.decoder.bind(response).single;
throw ShlinkException.fromJson(response.statusCode, sBody);
}

/// Delete the tags given in [lstTags]
Future<bool> deleteTags(List<String> lstTags) async {
String sUrl = '$_url$_API_PATH/tags';

if (lstTags == null && lstTags.isEmpty) {
return false;
}

bool bFirst = true;
for (String sTag in lstTags) {
if (bFirst) {
sUrl += '?';
bFirst = false;
} else {
sUrl += '&';
}

sUrl += 'tags[]=${Uri.encodeQueryComponent(sTag)}';
}

HttpClientRequest request = await HttpClient().deleteUrl(Uri.parse(sUrl))
..headers.contentType = ContentType.json
..headers.set(_HEADER_API_KEY, _apiKey);

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 217c4d5

Please sign in to comment.