listContacts method

Future<ResendResult<ResendListContactsResponse>> listContacts(
  1. String audienceId
)

Show all contacts from an audience.

Implementation

Future<ResendResult<ResendListContactsResponse>> listContacts(
    String audienceId) async {
  // Validation
  assert(audienceId.isNotEmpty, 'The audience ID can not be empty.');

  // Construct the request URI
  final Uri uri = Uri(
      scheme: _baseUri.scheme,
      host: _baseUri.host,
      path: '${_baseUri.path}/$audienceId/contacts');

  // Send GET request to the API
  final http.Response response = await http.get(uri,
      headers: <String, String>{
        'Authorization': 'Bearer $_apiKey',
        'Content-Type': 'application/json'
      });

  // Decode the response
  final Json body = json.decode(response.body);

  // Return Failure when statusCode is not OK
  if (response.statusCode != 200) {
    return ResendFailure.fromJson(body);
  }

  // Return parsed data when statusCode is OK
  final ResendListContactsResponse result =
      ResendListContactsResponse.fromJson(body);
  return ResendResult<ResendListContactsResponse>.success(result);
}