You are here

public function DataApi::deleteEvent in Acquia Lift Connector 8

Deletes an event from Acquia Lift Data

Parameters

$event_name: The name of the event.

Throws

DataApiException

File

src/Service/Api/DataApi.php, line 236
Contains \Drupal\acquia_lift\Service\Api\DataApi.

Class

DataApi

Namespace

Drupal\acquia_lift\Service\Api

Code

public function deleteEvent($event_name) {

  // First get our Authorization header.
  $url = $this
    ->generateEndpoint('events/' . $event_name);
  $auth_header = $this
    ->getAuthHeader('DELETE', $url);
  $request = new Request('DELETE', $url, [
    'Authorization' => $auth_header,
  ]);
  $response = $this->httpClient
    ->send($request);
  $vars = [
    '@eventname' => $event_name,
  ];
  $success_msg = SafeMarkup::format('The event @eventname was deleted from Acquia Lift Profiles', $vars);
  $fail_msg = SafeMarkup::format('Could not delete event @eventname from Acquia Lift Profiles', $vars);
  if ($response
    ->getStatusCode() != 200) {
    $this->logger
      ->error($fail_msg);
    throw new DataApiException($fail_msg);
  }
  $this->logger
    ->info($success_msg);
}