Skip to content

Commit

Permalink
Add tags
Browse files Browse the repository at this point in the history
  • Loading branch information
virtualmarc committed Feb 24, 2020
1 parent ca4a9f7 commit 34ba50f
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 @@ -2,6 +2,7 @@

- List short URL's
- List tags
- Add tags

## 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 @@ -246,4 +246,29 @@ class Shlink {
.map((t) => t.toString())
.toList();
}

/// Add new Tags from [lstTags]
Future<List<String>> addTags(List<String> lstTags) async {
String sUrl = '$_url$_API_PATH/tags';

Map<String, dynamic> mJsonReq = {'tags': lstTags};

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

HttpClientResponse response = await request.close();
String sBody = await utf8.decoder.bind(response).single;

if (response.statusCode != 200) {
throw ShlinkException.fromJson(response.statusCode, sBody);
}

Map<String, dynamic> mJsonResp = jsonDecode(sBody);

return (mJsonResp['tags']['data'] as List<dynamic>)
.map((t) => t.toString())
.toList();
}
}

0 comments on commit 34ba50f

Please sign in to comment.