Skip to content

Commit

Permalink
Fix Laravel SP, rename baseUrl to entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
danmichaelo committed Apr 14, 2021
1 parent 9421780 commit b43aa53
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ $alma = new AlmaClient('MY_SECRET_API_KEY', 'eu');
```

where `'eu'` is the region code for Europe (use `'na'` for North America or `'ap'` for Asia Pacific).
By default, the API base URL is generated from the region code,
but if you're connecting to the API through a proxy, you can set the base URL directly:
By default, the API entry point URL is generated from the region code,
but if you're connecting to the API through a proxy, you can configure a different URL:

```
$alma = new AlmaClient('MY_SECRET_API_KEY')
->setBaseUrl('https://gw-uio.intark.uh-it.no/alma/v1');
->setEntryPoint('https://gw-uio.intark.uh-it.no/alma/v1');
```

If your Alma instance is connected to a network zone and you want to work
Expand Down
16 changes: 8 additions & 8 deletions config/alma.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
// SRU URL for institution zone
'sru' => env('ALMA_IZ_SRU_URL'),

// Base URL for institution zone. This only needs to be specified if you
// use a proxy or other non-standard URL.
'baseUrl' => null,
// Entry point URL. This only needs to be specified if you use a proxy
// or other non-standard entry point.
'entrypoint' => null,

// Optional list of extra headers to send with each request.
'extraHeaders' => [
'headers' => [
// 'x-proxy-auth' => 'custom proxy auth'
],
],
Expand All @@ -43,12 +43,12 @@
// SRU URL for institution zone
'sru' => env('ALMA_NZ_SRU_URL'),

// Base URL for institution zone. This only needs to be specified if you
// use a proxy or other non-standard URL.
'baseUrl' => null,
// Entry point URL. This only needs to be specified if you use a proxy
// or other non-standard entry point.
'entrypoint' => null,

// Optional list of extra headers to send with each request.
'extraHeaders' => [
'headers' => [
// 'x-proxy-auth' => 'custom proxy auth'
],
],
Expand Down
4 changes: 2 additions & 2 deletions spec/ClientSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function let()
public function it_can_be_configured_with_custom_base_url()
{
$this->beConstructedWith('DummyKey');
$this->setBaseUrl('http://proxy.foxy');
$this->baseUrl->shouldBe('http://proxy.foxy');
$this->setEntryPoint('http://proxy.foxy');
$this->entrypoint->shouldBe('http://proxy.foxy');
}


Expand Down
26 changes: 13 additions & 13 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*/
class Client
{
public $baseUrl;
public $entrypoint;

/** @var string Alma zone (institution or network) */
public $zone;
Expand Down Expand Up @@ -89,7 +89,7 @@ class Client
public $sleepTimeOnServerError = 10;

/** @var array Extra request headers */
public $extraHeaders = [];
public $headers = [];

/**
* @var Conf
Expand All @@ -115,7 +115,7 @@ class Client
* Create a new client to connect to a given Alma instance.
*
* @param ?string $key API key
* @param string $region Hosted region code, used to build base URL
* @param string $region Hosted region code, used to build the entrypoint URL
* @param string $zone Alma zone (Either Zones::INSTITUTION or Zones::NETWORK)
* @param ?HttpClientInterface $http
* @param ?RequestFactoryInterface $requestFactory
Expand Down Expand Up @@ -228,33 +228,33 @@ public function setRegion($regionCode)
if (!in_array($regionCode, ['na', 'eu', 'ap'])) {
throw new AlmaClientException('Invalid region code');
}
$this->setBaseUrl('https://api-' . $regionCode . '.hosted.exlibrisgroup.com/almaws/v1');
$this->setEntryPoint('https://api-' . $regionCode . '.hosted.exlibrisgroup.com/almaws/v1');

return $this;
}

/**
* Set the Alma API base url.
*
* @param string $baseUrl
* @param string $url
* @return $this
*/
public function setBaseUrl(string $baseUrl)
public function setEntryPoint(string $url)
{
$this->baseUrl = $baseUrl;
$this->entrypoint = $url;

return $this;
}

/**
* Set extra request headers.
*
* @param array $extraHeaders
* @param array $headers
* @return $this
*/
public function setExtraHeaders(array $extraHeaders)
public function setExtraHeaders(array $headers)
{
$this->extraHeaders = $extraHeaders;
$this->headers = $headers;

return $this;
}
Expand All @@ -277,8 +277,8 @@ public function buildUrl($url, $query = [])

$url = $url[0];

if (strpos($url, $this->baseUrl) === false) {
$url = $this->baseUrl . $url;
if (strpos($url, $this->entrypoint) === false) {
$url = $this->entrypoint . $url;
}

return $this->uriFactory->createUri($url)
Expand All @@ -301,7 +301,7 @@ public function request(RequestInterface $request, $attempt = 1)
if (isset($this->key)) {
$request = $request->withHeader('Authorization', 'apikey ' . $this->key);
}
foreach ($this->extraHeaders as $key => $val) {
foreach ($this->headers as $key => $val) {
$request = $request->withHeader($key, $val);
}

Expand Down
12 changes: 6 additions & 6 deletions src/Laravel/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ public function register()
isset($app[UriFactoryInterface::class]) ? $app[UriFactoryInterface::class] : null
);

if ($app['config']->get('alma.iz.baseUrl')) {
$alma->setBaseUrl($app['config']->get('alma.iz.baseUrl'));
if ($app['config']->get('alma.iz.entrypoint')) {
$alma->setEntryPoint($app['config']->get('alma.iz.entrypoint'));
}
$alma->setExtraHeaders($app['config']->get('alma.extraHeaders', []));
$alma->setExtraHeaders($app['config']->get('alma.iz.headers', []));

// Set network zone key, if any
$alma->nz->setKey($app['config']->get('alma.nz.key'));

if ($app['config']->get('alma.nz.baseUrl')) {
$alma->nz->setBaseUrl($app['config']->get('alma.nz.baseUrl'));
if ($app['config']->get('alma.nz.entrypoint')) {
$alma->nz->setEntryPoint($app['config']->get('alma.nz.entrypoint'));
}
$alma->nz->setExtraHeaders($app['config']->get('alma.nz.extraHeaders', []));
$alma->nz->setExtraHeaders($app['config']->get('alma.nz.headers', []));

// Optionally, attach SRU client for institution zone
if ($app['config']->get('alma.iz.sru')) {
Expand Down

0 comments on commit b43aa53

Please sign in to comment.