You are here

public function Project::__construct in GatherContent 8.3

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

Account constructor.

Parameters

string $username: API username.

string $api_key: API key.

bool $local: Indicates, if we will need to have client object.

File

src/DAO/Project.php, line 27

Class

Project
Class Project.

Namespace

Drupal\gathercontent\DAO

Code

public function __construct($username = NULL, $api_key = NULL, $local = FALSE) {
  $this->local = $local;
  if (!$local) {
    if (is_null($username)) {
      $username = \Drupal::config('gathercontent.settings')
        ->get('gathercontent_username');
    }
    if (is_null($api_key)) {
      $api_key = \Drupal::config('gathercontent.settings')
        ->get('gathercontent_api_key');
    }
    if (empty($username) || empty($api_key)) {
      \Drupal::logger('gathercontent')
        ->error("Trying to call API without credentials.", []);
    }
    $this->client = new Client([
      'base_uri' => 'https://api.gathercontent.com',
      'auth' => [
        $username,
        $api_key,
      ],
      'headers' => [
        'Accept' => 'application/vnd.gathercontent.v0.5+json',
      ],
    ]);
  }
}