You are here

public function MailgunHandler::validateMailgunApiKey in Mailgun 8

Validates Mailgun API key.

Parameters

string $key: The API key.

Return value

bool Whether the API key is valid.

Overrides MailgunHandlerInterface::validateMailgunApiKey

1 call to MailgunHandler::validateMailgunApiKey()
MailgunHandler::validateMailgunApiSettings in src/MailgunHandler.php
Checks if API settings are correct and not empty.

File

src/MailgunHandler.php, line 192

Class

MailgunHandler
Mail handler to send out an email message array to the Mailgun API.

Namespace

Drupal\mailgun

Code

public function validateMailgunApiKey($key) {
  if (!$this
    ->validateMailgunLibrary()) {
    return FALSE;
  }
  $mailgun = Mailgun::create($key);
  try {
    $mailgun
      ->domains()
      ->index();
  } catch (Exception $e) {
    return FALSE;
  }
  return TRUE;
}