getGifByID method

Future<SuccessResponseSingleModel> getGifByID(
  1. String gifID, {
  2. Rating? rating,
})

Get a gif from an ID Get GIF by ID returns a GIF’s metadata based on the GIF ID specified.

Implementation

Future<SuccessResponseSingleModel> getGifByID(
  String gifID, {
  Rating? rating,
}) async {
  // Verify if rating is not "y"
  if (rating == Rating.y) {
    throw Exception('Rating "y" is not supported for getGifByID endpoint');
  }

  const baseUrl = GiphyAPIPath.baseUrl;

  final pathSegments = [
    GiphyAPIPath.version1,
    GiphyAPIPath.gif,
    GiphyAPIPath.gifByID(gifID),
  ];

  Map<String, dynamic> queryParameters = {
    'api_key': apiKey,
  };

  if (rating != null) {
    queryParameters['rating'] = rating.apiValue;
  }

  if (randomID != null) {
    queryParameters['random_id'] = randomID;
  }

  // Make the request

  final responseMap = await GiphyApiManager.get(
    baseUrl,
    pathSegments,
    queryParameters: queryParameters,
    debugMode: debugMode,
  );

  // Parse the response

  return SuccessResponseSingleModel.fromJson(responseMap);
}