Skip to content
Snippets Groups Projects
Commit 20762471 authored by Demian Katz's avatar Demian Katz
Browse files

Very basic Libguides2 support.

- Resolves VUFIND-1029.
parent 8fa45ae7
No related merge requests found
......@@ -3,9 +3,12 @@
; HTTP timeout
timeout = 30
; Your institution id
; Your institution id (called site id in api version 2; may have changed w/ upgrade)
iid = my-id
; API version to use (1 or 2)
version = 1
; This section controls the result limit options for search results. default_limit
; sets the default number of results per page. limit_options is a comma-separated
; list of numbers to be presented to the end-user. If only one limit is required,
......
......@@ -120,12 +120,16 @@ class LibGuidesBackendFactory implements FactoryInterface
$iid = isset($this->libGuidesConfig->General->iid)
? $this->libGuidesConfig->General->iid : null;
// Pick version:
$ver = isset($this->libGuidesConfig->General->version)
? $this->libGuidesConfig->General->version : 1;
// Build HTTP client:
$client = $this->serviceLocator->get('VuFind\Http')->createClient();
$timeout = isset($this->libGuidesConfig->General->timeout)
? $this->libGuidesConfig->General->timeout : 30;
$client->setOptions(array('timeout' => $timeout));
$connector = new Connector($iid, $client);
$connector = new Connector($iid, $client, $ver);
$connector->setLogger($this->logger);
return $connector;
}
......
......@@ -71,17 +71,30 @@ class Connector
*/
protected $host;
/**
* API version number
*
* @var float
*/
protected $apiVersion;
/**
* Constructor
*
* Sets up the LibGuides Client
*
* @param string $iid Institution ID
* @param HttpClient $client HTTP client
* @param string $iid Institution ID
* @param HttpClient $client HTTP client
* @param float $apiVersion API version number
*/
public function __construct($iid, $client)
public function __construct($iid, $client, $apiVersion = 1)
{
$this->host = "http://api.libguides.com/api_search.php?";
$this->apiVersion = $apiVersion;
if ($this->apiVersion < 2) {
$this->host = "http://api.libguides.com/api_search.php?";
} else {
$this->host = "http://lgapi.libapps.com/widgets.php?";
}
$this->iid = $iid;
$this->client = $client;
}
......@@ -113,14 +126,7 @@ class Connector
*/
public function query(array $params, $offset = 0, $limit = 20, $returnErr = true)
{
// defaults for params
$args = array(
'iid' => $this->iid,
'type' => 'guides',
'more' => 'false',
'sortby' => 'relevance',
);
$args = array_merge($args, $params);
$args = $this->prepareParams($params);
// run search, deal with exceptions
try {
......@@ -210,4 +216,46 @@ class Connector
return $results;
}
/**
* Prepare API parameters
*
* @param array $params Incoming parameters
*
* @return array
*/
protected function prepareParams(array $params)
{
// defaults for params (vary by version)
if ($this->apiVersion < 2) {
$args = array(
'iid' => $this->iid,
'type' => 'guides',
'more' => 'false',
'sortby' => 'relevance',
);
} else {
$args = array(
'site_id' => $this->iid,
'sort_by' => 'relevance',
'widget_type' => 1,
'search_match' => 2,
'search_type' => 0,
'sort_by' => 'relevance',
'list_format' => 1,
'output_format' => 1,
'load_type' => 2,
'enable_description' => 0,
'enable_group_search_limit' => 0,
'enable_subject_search_limit' => 0,
'widget_embed_type' => 2,
);
// remap v1 --> v2 params:
if (isset($params['search'])) {
$params['search_terms'] = $params['search'];
unset($params['search']);
}
}
return array_merge($args, $params);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment