You are here

private function AmazonSes::getSendStatistics in Amazon SES 7.2

Call Query API action GetSendStatistics.

The result is a list of data points, representing the last two weeks of sending activity. Each data point in the list contains statistics for a 15 minute interval. This action is throttled at one request per second.

1 call to AmazonSes::getSendStatistics()
AmazonSes::performServiceAction in src/AmazonSes.php
Add required parameter & header to the Query according to Query action.

File

src/AmazonSes.php, line 183
Class for interacting with Amazon SES service.

Class

AmazonSes
Modify the drupal mail system to use Amazon SES.

Namespace

Drupal\amazon_ses

Code

private function getSendStatistics($action_parameter) {
  $result['error'] = FALSE;
  try {
    $response = $this->sesClient
      ->getSendStatistics([]);
    if (!empty($response['SendDataPoints'])) {

      // Number of emails that have been enqueued for sending.
      $result['DeliveryAttempts'] = 0;

      // Number of emails rejected by Amazon SES.
      $result['Rejects'] = 0;

      // Number of emails that have bounced.
      $result['Bounces'] = 0;

      // Number of unwanted emails that were rejected by recipients.
      $result['Complaints'] = 0;
      foreach ($response['SendDataPoints'] as $value) {
        $result['DeliveryAttempts'] = check_plain($value['DeliveryAttempts']) + $result['DeliveryAttempts'];
        $result['Rejects'] = check_plain($value['Rejects']) + $result['Rejects'];
        $result['Bounces'] = check_plain($value['Bounces']) + $result['Bounces'];
        $result['Complaints'] = check_plain($value['Complaints']) + $result['Complaints'];
      }
    }
  } catch (\Aws\Ses\Exception\SesException $e) {
    $result['message'] = $e
      ->getAwsErrorType();
    $result['errorCode'] = $e
      ->getAwsErrorCode();
    $result['error'] = TRUE;
  }

  /* // Parse the xml response.
      $response = $response_xml->body->to_stdClass();
      if ($response_xml->status == '200') {
        $result['status'] = AMAZON_SES_REQUEST_SUCCESS;

        // Number of emails that have been enqueued for sending.
        $result['DeliveryAttempts'] = 0;
        // Number of emails rejected by Amazon SES.
        $result['Rejects'] = 0;
        // Number of emails that have bounced.
        $result['Bounces'] = 0;
        // Number of unwanted emails that were rejected by recipients.
        $result['Complaints'] = 0;
        if (isset($response->GetSendStatisticsResult->SendDataPoints->member)) {
          $member = $response->GetSendStatisticsResult->SendDataPoints->member;
          if (is_array($member)) {
            foreach ($member as $value) {
              $result['DeliveryAttempts'] = check_plain($value->DeliveryAttempts) + $result['DeliveryAttempts'];
              $result['Rejects'] = check_plain($value->Rejects) + $result['Rejects'];
              $result['Bounces'] = check_plain($value->Bounces) + $result['Bounces'];
              $result['Complaints'] = check_plain($value->Complaints) + $result['Complaints'];
            }
          }
          else {
            $result['DeliveryAttempts'] = check_plain($member->DeliveryAttempts);
            $result['Rejects'] = check_plain($member->Rejects);
            $result['Bounces'] = check_plain($member->Bounces);
            $result['Complaints'] = check_plain($member->Complaints);
          }

        }
      }
      // Error in response.
      else {
        $result['status'] = AMAZON_SES_REQUEST_FALIURE;
      }*/
  return $result;
}