retrieveBitLyLink method
Official Documentation :- Returns information for the specified link...
It will Return BitLyLinkData after successful operation. And throws BitLyException on unsuccessful operation.
Example:--
try{
final shortener = BitLyShortener(
accessToken: "YOUR_TOKEN",
);
BitLyLinkData linkData=await shortener.retrieveBitLyLink(link: 'bit.ly/9999');
print(linkData.link);
}
on BitLyException catch(e){ //For handling BitLyException
print(e);
}
on Exception catch(e){ // For handling other Exceptions related to http package
print(e);
}
Check out official documentation for more info.
Implementation
Future<BitLyLinkData> retrieveBitLyLink({
///Link must be a valid bitly link.
///else it would throw [FormatException]
///
///This link can be extracted from [BitLyLinkData]'s id field.
///example:-
/// --- bit.ly/234sxsd4
required String link,
}) async {
final response = await get(
Uri.parse("$_bitlinkUri/$link"),
headers: {
_contentTypeHeader: _jsonContentType,
_authHeader: "Bearer $accessToken",
},
);
if (response.statusCode == 200 || response.statusCode == 201) {
final _linkData = jsonDecode(response.body);
return BitLyLinkData.fromMap(_linkData);
} else {
final _errorData = jsonDecode(response.body);
throw BitLyException(_errorData);
}
}