getTrending method

Future<SuccessResponseMultiModel> getTrending({
  1. int limit = 25,
  2. int offset = 0,
  3. Rating? rating,
  4. Bundle? bundle,
  5. bool sticker = false,
})

Get Gifs or Stockers Trending GIPHY Trending returns a list of the most relevant and engaging content each and every day.

Implementation

Future<SuccessResponseMultiModel> getTrending({
  int limit = 25,
  int offset = 0,
  Rating? rating,
  Bundle? bundle,
  bool sticker = false,
}) async {
  // Verify if rating is not "y"
  if (rating == Rating.y) {
    throw Exception('Rating "y" is not supported for trending 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,
    sticker ? GiphyAPIPath.stickers : GiphyAPIPath.gif,
    GiphyAPIPath.trending,
  ];

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

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

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

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

  // Make the request

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

  // Parse the response

  return SuccessResponseMultiModel.fromJson(responseMap);
}