Skip to content
Snippets Groups Projects
Commit 8005c782 authored by Ere Maijala's avatar Ere Maijala Committed by Robert Lange
Browse files

SierraRest: Use REST API v5 by default. (#1659)

- v3 is deprecated and will be removed in a future release.
parent 8f7ca5de
No related merge requests found
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* *
* PHP version 7 * PHP version 7
* *
* Copyright (C) The National Library of Finland 2016-2019. * Copyright (C) The National Library of Finland 2016-2020.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2, * it under the terms of the GNU General Public License version 2,
...@@ -153,10 +153,23 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface, ...@@ -153,10 +153,23 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface,
* v5.1 (technically still v5 but added in a later revision): * v5.1 (technically still v5 but added in a later revision):
* - summary holdings information (especially for serials) * - summary holdings information (especially for serials)
* *
* Note that API version 3 is deprecated in Sierra 5.1 and will be removed later
* on (reported March 2020).
*
* @var int * @var int
*/ */
protected $apiVersion = 5; protected $apiVersion = 5;
/**
* API base path
*
* This is the default API level used even if apiVersion is higher so that any
* changes in existing methods don't cause trouble.
*
* @var string
*/
protected $apiBase = 'v5';
/** /**
* Whether to sort items by enumchron. Default is true. * Whether to sort items by enumchron. Default is true.
* *
...@@ -247,6 +260,10 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface, ...@@ -247,6 +260,10 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface,
if (isset($this->config['Catalog']['api_version'])) { if (isset($this->config['Catalog']['api_version'])) {
$this->apiVersion = $this->config['Catalog']['api_version']; $this->apiVersion = $this->config['Catalog']['api_version'];
// Default to API v5 unless a lower compatibility level is needed.
if ($this->apiVersion < 5) {
$this->apiBase = 'v' . floor($this->apiVersion);
}
} }
$this->sortItemsByEnumChron $this->sortItemsByEnumChron
...@@ -397,7 +414,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface, ...@@ -397,7 +414,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface,
// which verifies the PIN code). // which verifies the PIN code).
$result = $this->makeRequest( $result = $this->makeRequest(
['v3', 'info', 'token'], [$this->apiBase, 'info', 'token'],
[], [],
'GET', 'GET',
['cat_username' => $username, 'cat_password' => $password] ['cat_username' => $username, 'cat_password' => $password]
...@@ -411,7 +428,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface, ...@@ -411,7 +428,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface,
$patronId = $result['patronId']; $patronId = $result['patronId'];
$result = $this->makeRequest( $result = $this->makeRequest(
['v3', 'patrons', $patronId], [$this->apiBase, 'patrons', $patronId],
['fields' => 'names,emails'], ['fields' => 'names,emails'],
'GET', 'GET',
['cat_username' => $username, 'cat_password' => $password] ['cat_username' => $username, 'cat_password' => $password]
...@@ -479,7 +496,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface, ...@@ -479,7 +496,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface,
public function getMyProfile($patron) public function getMyProfile($patron)
{ {
$result = $this->makeRequest( $result = $this->makeRequest(
['v3', 'patrons', $patron['id']], [$this->apiBase, 'patrons', $patron['id']],
[ [
'fields' => 'names,emails,phones,addresses,expirationDate' 'fields' => 'names,emails,phones,addresses,expirationDate'
], ],
...@@ -546,7 +563,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface, ...@@ -546,7 +563,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface,
$offset = isset($params['page']) ? ($params['page'] - 1) * $pageSize : 0; $offset = isset($params['page']) ? ($params['page'] - 1) * $pageSize : 0;
$result = $this->makeRequest( $result = $this->makeRequest(
['v3', 'patrons', $patron['id'], 'checkouts'], [$this->apiBase, 'patrons', $patron['id'], 'checkouts'],
[ [
'limit' => $pageSize, 'limit' => $pageSize,
'offset' => $offset, 'offset' => $offset,
...@@ -584,7 +601,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface, ...@@ -584,7 +601,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface,
} }
// Fetch item information // Fetch item information
$item = $this->makeRequest( $item = $this->makeRequest(
['v3', 'items', $transaction['item_id']], [$this->apiBase, 'items', $transaction['item_id']],
['fields' => 'bibIds,varFields'], ['fields' => 'bibIds,varFields'],
'GET', 'GET',
$patron $patron
...@@ -644,7 +661,9 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface, ...@@ -644,7 +661,9 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface,
foreach ($renewDetails['details'] as $details) { foreach ($renewDetails['details'] as $details) {
list($checkoutId, $itemId) = explode('|', $details); list($checkoutId, $itemId) = explode('|', $details);
$result = $this->makeRequest( $result = $this->makeRequest(
['v3', 'patrons', 'checkouts', $checkoutId, 'renewal'], [], 'POST', [$this->apiBase, 'patrons', 'checkouts', $checkoutId, 'renewal'],
[],
'POST',
$patron $patron
); );
if (!empty($result['code'])) { if (!empty($result['code'])) {
...@@ -690,7 +709,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface, ...@@ -690,7 +709,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface,
$sortOrder = isset($params['sort']) && 'checkout asc' === $params['sort'] $sortOrder = isset($params['sort']) && 'checkout asc' === $params['sort']
? 'asc' : 'desc'; ? 'asc' : 'desc';
$result = $this->makeRequest( $result = $this->makeRequest(
['v3', 'patrons', $patron['id'], 'checkouts', 'history'], [$this->apiBase, 'patrons', $patron['id'], 'checkouts', 'history'],
[ [
'limit' => $pageSize, 'limit' => $pageSize,
'offset' => $offset, 'offset' => $offset,
...@@ -720,7 +739,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface, ...@@ -720,7 +739,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface,
]; ];
// Fetch item information // Fetch item information
$item = $this->makeRequest( $item = $this->makeRequest(
['v3', 'items', $transaction['item_id']], [$this->apiBase, 'items', $transaction['item_id']],
['fields' => 'bibIds,varFields'], ['fields' => 'bibIds,varFields'],
'GET', 'GET',
$patron $patron
...@@ -769,7 +788,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface, ...@@ -769,7 +788,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface,
$fields .= ',pickupByDate'; $fields .= ',pickupByDate';
} }
$result = $this->makeRequest( $result = $this->makeRequest(
['v3', 'patrons', $patron['id'], 'holds'], [$this->apiBase, 'patrons', $patron['id'], 'holds'],
[ [
'limit' => 10000, 'limit' => 10000,
'fields' => $fields 'fields' => $fields
...@@ -791,7 +810,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface, ...@@ -791,7 +810,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface,
$itemId = $this->extractId($entry['record']); $itemId = $this->extractId($entry['record']);
// Fetch bib ID from item // Fetch bib ID from item
$item = $this->makeRequest( $item = $this->makeRequest(
['v3', 'items', $itemId], [$this->apiBase, 'items', $itemId],
['fields' => 'bibIds,varFields'], ['fields' => 'bibIds,varFields'],
'GET', 'GET',
$patron $patron
...@@ -1098,7 +1117,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface, ...@@ -1098,7 +1117,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface,
} }
$result = $this->makeRequest( $result = $this->makeRequest(
[$comment ? 'v4' : 'v3', 'patrons', $patron['id'], 'holds', 'requests'], [$this->apiBase, 'patrons', $patron['id'], 'holds', 'requests'],
json_encode($request), json_encode($request),
'POST', 'POST',
$patron $patron
...@@ -1124,7 +1143,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface, ...@@ -1124,7 +1143,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface,
public function getMyFines($patron) public function getMyFines($patron)
{ {
$result = $this->makeRequest( $result = $this->makeRequest(
['v3', 'patrons', $patron['id'], 'fines'], [$this->apiBase, 'patrons', $patron['id'], 'fines'],
[ [
'fields' => 'item,assessedDate,description,chargeType,itemCharge' 'fields' => 'item,assessedDate,description,chargeType,itemCharge'
. ',processingFee,billingFee,paidAmount' . ',processingFee,billingFee,paidAmount'
...@@ -1165,7 +1184,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface, ...@@ -1165,7 +1184,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface,
$itemId = $this->extractId($entry['item']); $itemId = $this->extractId($entry['item']);
// Fetch bib ID from item // Fetch bib ID from item
$item = $this->makeRequest( $item = $this->makeRequest(
['v3', 'items', $itemId], [$this->apiBase, 'items', $itemId],
['fields' => 'bibIds'], ['fields' => 'bibIds'],
'GET', 'GET',
$patron $patron
...@@ -1230,7 +1249,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface, ...@@ -1230,7 +1249,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface,
$request = ['pin' => $newPIN]; $request = ['pin' => $newPIN];
$result = $this->makeRequest( $result = $this->makeRequest(
['v3', 'patrons', $patron['id']], [$this->apiBase, 'patrons', $patron['id']],
json_encode($request), json_encode($request),
'PUT', 'PUT',
$patron $patron
...@@ -1692,7 +1711,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface, ...@@ -1692,7 +1711,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface,
$result = null; $result = null;
while (null === $result || $limit === $result['total']) { while (null === $result || $limit === $result['total']) {
$result = $this->makeRequest( $result = $this->makeRequest(
['v3', 'items'], [$this->apiBase, 'items'],
[ [
'bibIds' => $this->extractBibId($id), 'bibIds' => $this->extractBibId($id),
'deleted' => 'false', 'deleted' => 'false',
...@@ -2136,7 +2155,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface, ...@@ -2136,7 +2155,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface,
$blockReason = $this->getCachedData($cacheId); $blockReason = $this->getCachedData($cacheId);
if (null === $blockReason) { if (null === $blockReason) {
$result = $this->makeRequest( $result = $this->makeRequest(
['v3', 'patrons', $patronId], [$this->apiBase, 'patrons', $patronId],
['fields' => 'blockInfo'], ['fields' => 'blockInfo'],
'GET', 'GET',
$patron $patron
...@@ -2246,7 +2265,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface, ...@@ -2246,7 +2265,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface,
protected function getBibRecord($id, $fields, $patron = false) protected function getBibRecord($id, $fields, $patron = false)
{ {
return $this->makeRequest( return $this->makeRequest(
['v3', 'bibs', $this->extractBibId($id)], [$this->apiBase, 'bibs', $this->extractBibId($id)],
['fields' => $fields], ['fields' => $fields],
'GET', 'GET',
$patron $patron
......
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