fetchTrendingGif method
Fetches a trending gif from the Giphy API.
It takes the apikey
, offset
, and language
as parameters.
Returns a Future that resolves to an Either type, containing a String error message or a GiphyGif object.
Implementation
Future<Either<String, GiphyGif>> fetchTrendingGif(
{required String apikey,
required int offset,
required String language}) async {
try {
final response = await _dio.get<Map<String, dynamic>>(
ApiConfig.trendingGifs(
apiKey: apikey, offset: offset, language: language),
);
if (response.statusCode == 200 && response.data != null) {
final giphyGif = GiphyGif.fromJson(
response.data!,
);
return Right(giphyGif);
} else {
return Left(response.statusMessage ?? 'Error');
}
} on DioException catch (e) {
return Left(e.toString());
}
}