channelSearch method

Future<SuccessChannelResponseModel> channelSearch(
  1. String query, {
  2. int limit = 25,
  3. int offset = 0,
})

Search a channel Channel Search endpoint returns all the GIPHY channels matching the query term

Implementation

Future<SuccessChannelResponseModel> channelSearch(
  String query, {
  int limit = 25,
  int offset = 0,
}) async {
  // Verify if limit is an Int32 value
  if (limit < 1 && limit > 50) {
    throw Exception('Limit must be an Int32 value and between 1 and 50');
  }

  // 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.channelSearch,
  ];

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

  // Make the request

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

  // Parse the response

  return SuccessChannelResponseModel.fromJson(responseMap);
}