call<T extends MandrillResponse> method

Future<T> call<T extends MandrillResponse>(
  1. String path,
  2. Map body,
  3. T responseCoding, {
  4. ResponseParser<T>? responseParser,
})

Implementation

Future<T> call<T extends MandrillResponse>(
    String path, Map body, T responseCoding,
    {ResponseParser<T>? responseParser}) async {
  final uri = Uri(
    scheme: options.scheme,
    host: options.host,
    port: options.port,
    path: '${options.pathPrefix}$path.json',
  );

  final bodyWithKey = Map.from(body)..['key'] = apiKey;

  _log.finer('Making Mandrill request to $uri');
  final responseMap =
      await request(uri, options.headers, jsonEncode(bodyWithKey));

  T response;
  if (responseParser == null) {
    response = defaultResponseParser<T>(responseCoding, responseMap);
  } else {
    response = responseParser(responseCoding, responseMap);
  }
  return response;
}