You are here

protected function SearchApiAlgoliaService::connect in Search API Algolia 7

Connect to the Algolia service.

Uses the application ID et API key provided in the UI.

2 calls to SearchApiAlgoliaService::connect()
SearchApiAlgoliaService::deleteItems in includes/service.inc
Implements deleteItems.
SearchApiAlgoliaService::indexItems in includes/service.inc
Implements indexItems.

File

includes/service.inc, line 37
Contains SearchApiAlgoliaService.

Class

SearchApiAlgoliaService
SearchApiAlgoliaService class.

Code

protected function connect($index) {

  // @todo Make the absence of lib more visible (error message on the status
  // report page for instance, and during the install process).
  if (($library = libraries_load('algolia')) && !empty($library['loaded'])) {
    if (defined('VERSION')) {
      \AlgoliaSearch\Version::addSuffixUserAgentSegment('Drupal', VERSION);
    }
    $version = '';
    if (function_exists($library['version callback'])) {
      $version = call_user_func($library['version callback']);
    }
    \AlgoliaSearch\Version::addSuffixUserAgentSegment('Drupal community module', $version);
    $algolia_client = new \AlgoliaSearch\Client($this
      ->getApplicationID(), $this
      ->getApiKey());
    $this
      ->setAlgoliaIndex($algolia_client
      ->initIndex($index->name));
  }
  else {
    throw new SearchApiException(t('Algolia library could not be found or did not load properly.'));
  }
}