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 ...@@ -7,7 +7,10 @@ timeout = 30
iid = my-id iid = my-id
; API version to use (1 or 2) ; 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 ; 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 ; sets the default number of results per page. limit_options is a comma-separated
......
...@@ -102,8 +102,7 @@ class LibGuidesBackendFactory implements FactoryInterface ...@@ -102,8 +102,7 @@ class LibGuidesBackendFactory implements FactoryInterface
*/ */
protected function createBackend(Connector $connector) protected function createBackend(Connector $connector)
{ {
$defaultSearch = isset($this->libGuidesConfig->General->defaultSearch) $defaultSearch = $this->libGuidesConfig->General->defaultSearch ?? null;
? $this->libGuidesConfig->General->defaultSearch : null;
$backend = new Backend( $backend = new Backend(
$connector, $this->createRecordCollectionFactory(), $defaultSearch $connector, $this->createRecordCollectionFactory(), $defaultSearch
); );
...@@ -120,20 +119,20 @@ class LibGuidesBackendFactory implements FactoryInterface ...@@ -120,20 +119,20 @@ class LibGuidesBackendFactory implements FactoryInterface
protected function createConnector() protected function createConnector()
{ {
// Load credentials: // Load credentials:
$iid = isset($this->libGuidesConfig->General->iid) $iid = $this->libGuidesConfig->General->iid ?? null;
? $this->libGuidesConfig->General->iid : null;
// Pick version: // Pick version:
$ver = isset($this->libGuidesConfig->General->version) $ver = $this->libGuidesConfig->General->version ?? 1;
? $this->libGuidesConfig->General->version : 1;
// Get base URI, if available:
$baseUrl = $this->libGuidesConfig->General->baseUrl ?? null;
// Build HTTP client: // Build HTTP client:
$client = $this->serviceLocator->get('VuFindHttp\HttpService') $client = $this->serviceLocator->get('VuFindHttp\HttpService')
->createClient(); ->createClient($baseUrl);
$timeout = isset($this->libGuidesConfig->General->timeout) $timeout = $this->libGuidesConfig->General->timeout ?? 30;
? $this->libGuidesConfig->General->timeout : 30;
$client->setOptions(['timeout' => $timeout]); $client->setOptions(['timeout' => $timeout]);
$connector = new Connector($iid, $client, $ver); $connector = new Connector($iid, $client, $ver, $baseUrl);
$connector->setLogger($this->logger); $connector->setLogger($this->logger);
return $connector; return $connector;
} }
......
...@@ -81,14 +81,18 @@ class Connector implements \Zend\Log\LoggerAwareInterface ...@@ -81,14 +81,18 @@ class Connector implements \Zend\Log\LoggerAwareInterface
* @param string $iid Institution ID * @param string $iid Institution ID
* @param HttpClient $client HTTP client * @param HttpClient $client HTTP client
* @param float $apiVersion API version number * @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; $this->apiVersion = $apiVersion;
if ($this->apiVersion < 2) { if (empty($baseUrl)) {
$this->host = "http://api.libguides.com/api_search.php?"; $this->host = ($this->apiVersion < 2)
? "http://api.libguides.com/api_search.php?"
: "http://lgapi.libapps.com/widgets.php?";
} else { } else {
$this->host = "http://lgapi.libapps.com/widgets.php?"; // Ensure appropriate number of question marks:
$this->host = rtrim($baseUrl, '?') . '?';
} }
$this->iid = $iid; $this->iid = $iid;
$this->client = $client; $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