You are here

public function Content::__construct in GatherContent 8

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

Account constructor.

Parameters

string $username: API username.

string $api_key: API key.

File

src/DAO/Content.php, line 29
Contains GatherContent\Accont class.

Class

Content
Class Account.

Namespace

Drupal\gathercontent\DAO

Code

public function __construct($username = NULL, $api_key = NULL) {
  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.", array());
  }
  $this->client = new Client(array(
    'base_uri' => 'https://api.gathercontent.com',
    'auth' => array(
      $username,
      $api_key,
    ),
    'headers' => array(
      'Accept' => 'application/vnd.gathercontent.v0.5+json',
    ),
  ));
}