updateDomain method

Future<ResendResult<ResendUpdateDomainResponse>> updateDomain(
  1. String domainId, {
  2. bool? clickTracking,
  3. bool? openTracking,
  4. ResendDomainTls? tls,
})

Update an existing domain.

Implementation

Future<ResendResult<ResendUpdateDomainResponse>> updateDomain(

    /// The Domain ID.
    String domainId,
    {
    /// Track clicks within the body of each HTML email.
    bool? clickTracking,

    /// Track the open rate of each email.
    bool? openTracking,

    /// - opportunistic: Opportunistic TLS means that it always attempts to make a secure connection to the receiving mail server. If it can’t establish a secure connection, it sends the message unencrypted.
    /// - enforced: Enforced TLS on the other hand, requires that the email communication must use TLS no matter what. If the receiving server does not support TLS, the email will not be sent.
    ResendDomainTls? tls}) async {
  // Validation
  assert(domainId.isNotEmpty, 'The domain ID can not be empty.');
  assert(clickTracking != null || openTracking != null || tls != null,
      'At least one optional parameter is required.');

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

  // Send GET request to the API
  final http.Response response = await http.patch(uri,
      headers: <String, String>{
        'Authorization': 'Bearer $_apiKey',
        'Content-Type': 'application/json'
      },
      body: jsonEncode(<String, dynamic>{
        if (clickTracking != null) 'click_tracking': clickTracking,
        if (openTracking != null) 'open_tracking': openTracking,
        if (tls != null) 'tls': tls.id
      }));

  // 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 ResendUpdateDomainResponse result =
      ResendUpdateDomainResponse.fromJson(body);
  return ResendResult<ResendUpdateDomainResponse>.success(result);
}