updateBitLyLink method
Official Documentation :- Updates fields in the specified link...
It will Return BitLyLinkData after successful operation. And throws BitLyException on unsuccessful operation.
Example:--
try{
final shortener = BitLyShortener(
accessToken: "YOUR_TOKEN",
);
final oldLinkData = BitLyLinkData(
link: "bit.ly/12323", //Must Not be Null||Empty
longUrl: "YOUR_LINK",
title: "title",
createdBy: "SamG",
);
BitLyLinkData linkData=await shortener.updateBitLyLink(linkData: oldLinkData);
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> updateBitLyLink({
///linkData must have a valid id field
required BitLyLinkData linkData,
}) async {
if (linkData.id == null ? true : linkData.id!.isEmpty)
throw Exception(
"id Must Not be Null Or Empty ",
);
final _body = linkData.toString();
final response = await patch(
Uri.parse("$_bitlinkUri/${linkData.id}"),
body: _body,
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);
}
}