Skip to content

Commit

Permalink
List tags
Browse files Browse the repository at this point in the history
  • Loading branch information
virtualmarc committed Feb 24, 2020
1 parent 07a3c72 commit ca4a9f7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 0.3.0

- List short URL's
- List tags

## 0.2.0

Expand Down
22 changes: 22 additions & 0 deletions lib/src/shlink_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,26 @@ class Shlink {

return lstShortUrls;
}

/// List all Tags
Future<List<String>> listTags() async {
String sUrl = '$_url$_API_PATH/tags';

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

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> mJson = jsonDecode(sBody);

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

0 comments on commit ca4a9f7

Please sign in to comment.