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

Make LibGuides base URL configurable, update defaults.

- Use SSL endpoint URL and version 2 in default configuration.
- Retain version 1 as default in code for backward compatibility.
- Resolves VUFIND-1225.
parent 386b397e
No related merge requests found
......@@ -7,7 +7,10 @@ timeout = 30
iid = my-id
; API version to use (1 or 2)
version = 1
version = 2
; Base URL for API
baseUrl = https://lgapi.libapps.com/widgets.php
; 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
......
......@@ -102,8 +102,7 @@ class LibGuidesBackendFactory implements FactoryInterface
*/
protected function createBackend(Connector $connector)
{
$defaultSearch = isset($this->libGuidesConfig->General->defaultSearch)
? $this->libGuidesConfig->General->defaultSearch : null;
$defaultSearch = $this->libGuidesConfig->General->defaultSearch ?? null;
$backend = new Backend(
$connector, $this->createRecordCollectionFactory(), $defaultSearch
);
......@@ -120,20 +119,20 @@ class LibGuidesBackendFactory implements FactoryInterface
protected function createConnector()
{
// Load credentials:
$iid = isset($this->libGuidesConfig->General->iid)
? $this->libGuidesConfig->General->iid : null;
$iid = $this->libGuidesConfig->General->iid ?? null;
// Pick version:
$ver = isset($this->libGuidesConfig->General->version)
? $this->libGuidesConfig->General->version : 1;
$ver = $this->libGuidesConfig->General->version ?? 1;
// Get base URI, if available:
$baseUrl = $this->libGuidesConfig->General->baseUrl ?? null;
// Build HTTP client:
$client = $this->serviceLocator->get('VuFindHttp\HttpService')
->createClient();
$timeout = isset($this->libGuidesConfig->General->timeout)
? $this->libGuidesConfig->General->timeout : 30;
->createClient($baseUrl);
$timeout = $this->libGuidesConfig->General->timeout ?? 30;
$client->setOptions(['timeout' => $timeout]);
$connector = new Connector($iid, $client, $ver);
$connector = new Connector($iid, $client, $ver, $baseUrl);
$connector->setLogger($this->logger);
return $connector;
}
......
......@@ -81,14 +81,18 @@ class Connector implements \Zend\Log\LoggerAwareInterface
* @param string $iid Institution ID
* @param HttpClient $client HTTP client
* @param float $apiVersion API version number
* @param string $baseUrl API base URL (optional)
*/
public function __construct($iid, $client, $apiVersion = 1)
public function __construct($iid, $client, $apiVersion = 1, $baseUrl = null)
{
$this->apiVersion = $apiVersion;
if ($this->apiVersion < 2) {
$this->host = "http://api.libguides.com/api_search.php?";
if (empty($baseUrl)) {
$this->host = ($this->apiVersion < 2)
? "http://api.libguides.com/api_search.php?"
: "http://lgapi.libapps.com/widgets.php?";
} else {
$this->host = "http://lgapi.libapps.com/widgets.php?";
// Ensure appropriate number of question marks:
$this->host = rtrim($baseUrl, '?') . '?';
}
$this->iid = $iid;
$this->client = $client;
......
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