You are here

public function Account::getAccounts in GatherContent 8.3

Same name and namespace in other branches
  1. 8 src/DAO/Account.php \Drupal\gathercontent\DAO\Account::getAccounts()

Get list of accounts.

Return value

array Array with accounts.

File

src/DAO/Account.php, line 61

Class

Account
Class Account.

Namespace

Drupal\gathercontent\DAO

Code

public function getAccounts() {
  $accounts = [];
  try {
    $response = $this->client
      ->get('/accounts');
    if ($response
      ->getStatusCode() === 200) {
      $data = json_decode($response
        ->getBody());
      $accounts = $data->data;
    }
    else {
      drupal_set_message(t("User with provided credentials wasn't found."), 'error');
      $accounts = NULL;
    }
  } catch (\Exception $e) {
    \Drupal::logger('gathercontent')
      ->error($e
      ->getMessage(), []);
    drupal_set_message(t("User with provided credentials wasn't found. 1"), 'error');
    $accounts = NULL;
  }
  return $accounts;
}