shortenUrl method
Shortens the provided url
. An optional code
can be provided to create
your own vanity URL.
Implementation
Future<String> shortenUrl(String url, {String? code}) {
final params = <String, dynamic>{};
params['url'] = url;
if (code != null) {
params['code'] = code;
}
return github
.request('POST', 'http://git.io/', params: params)
.then((response) {
if (response.statusCode != StatusCodes.CREATED) {
throw GitHubError(github, 'Failed to create shortened url!');
}
return response.headers['Location']!.split('/').last;
});
}