getMultipleGifsByID method

Future<SuccessResponseMultiModel> getMultipleGifsByID(
  1. List<String> gifsID, {
  2. Rating? rating,
  3. int limit = 25,
  4. int offset = 0,
})

Get multiple gifs from an IDs Get GIFs by ID returns metadata of multiple GIFs based on the GIF IDs specified.

Implementation

Future<SuccessResponseMultiModel> getMultipleGifsByID(
  List<String> gifsID, {
  Rating? rating,
  int limit = 25,
  int offset = 0,
}) async {
  // Verify if rating is not "y"
  if (rating == Rating.y) {
    throw Exception('Rating "y" is not supported for getGifByID endpoint');
  }

  // Verify if limit is an Int32 value
  if (!limit.isInt32 && limit < 1) {
    throw Exception('Limit must be an Int32 value and greater than 0');
  }

  // Verify if offset is an Int32 value
  if (!offset.isInt32 && offset < 0) {
    throw Exception(
      'Offset must be an Int32 value and greater than or equal to 0',
    );
  }

  const baseUrl = GiphyAPIPath.baseUrl;

  final pathSegments = [
    GiphyAPIPath.version1,
    GiphyAPIPath.gif,
  ];

  Map<String, dynamic> queryParameters = {
    'api_key': apiKey,
    "ids": gifsID.join(","),
    'limit': limit.toString(),
    'offset': offset.toString(),
  };

  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 SuccessResponseMultiModel.fromJson(responseMap);
}