Skip to content

Commit

Permalink
Revert the loan pagination bump
Browse files Browse the repository at this point in the history
Turns out this is limited to 100 and the API just returns 100
and ignores the offset then.

Add some extra error handling so this doesn't happen again.
  • Loading branch information
lazka committed Jun 27, 2024
1 parent 784149b commit 34bb031
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Service/AlmaApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ public function getBookLoansJsonDataByPerson(Person $person): ?array
try {
$resultList = [];
$loopCount = 0;
$limit = 1000;
$limit = 100;
$offset = 0;

// do as many requests as necessary to get all loans by the user
Expand Down
6 changes: 5 additions & 1 deletion src/Service/AlmaUrlApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,12 @@ public function getBookOfferLoansUrl(string $identifier): string
/**
* @throws UriException
*/
public function getLoansByUserIdUrl(string $userId, int $limit = 1000, int $offset = 0): string
public function getLoansByUserIdUrl(string $userId, int $limit = 100, int $offset = 0): string
{
if ($limit < 0 || $limit > 100) {
throw new \RuntimeException('Valid values are 0-100');
}

// see: https://developers.exlibrisgroup.com/alma/apis/docs/users/R0VUIC9hbG1hd3MvdjEvdXNlcnMve3VzZXJfaWR9L2xvYW5z/
$uriTemplate = new UriTemplate('users/{userId}/loans{?limit,offset}');

Expand Down
2 changes: 1 addition & 1 deletion tests/AlmaApiUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function testGetBookOfferLoansUrl()
public function testGetLoansByUserIdUrl()
{
$this->assertEquals(
'users/bla%3F/loans?limit=1000&offset=0',
'users/bla%3F/loans?limit=100&offset=0',
$this->urls->getLoansByUserIdUrl('bla?'));
$this->assertEquals(
'users/bla%3F/loans?limit=20&offset=0',
Expand Down

0 comments on commit 34bb031

Please sign in to comment.