Skip to content

Commit 5b29f82

Browse files
committed
Add user requests
1 parent f49528c commit 5b29f82

File tree

13 files changed

+238
-3
lines changed

13 files changed

+238
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2828
- Analytics: The `getRows()` method is deprecated. Iterate over the `Report` instead.
2929
- Made package auto-discoverable in Laravel 5.5+.
3030
- Added helper method `Users::findOne()` to get the first match from a search.
31+
- Added support for retrieving user requests from `Bib`, `Item` and `User`.
3132

3233
### Changed
3334

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ If the package doesn't fit your needs, you might take a look at the alternative
1414

1515
## Table of Contents
1616

17+
* [Table of Contents](#table-of-contents)
1718
* [Install using Composer](#install-using-composer)
1819
* [Initializing a client](#initializing-a-client)
1920
* [Quick intro](#quick-intro)
@@ -26,8 +27,11 @@ If the package doesn't fit your needs, you might take a look at the alternative
2627
* [Editing records](#editing-records)
2728
* [Holdings and items](#holdings-and-items)
2829
* [Items](#items)
29-
* [Users and loans](#users-and-loans)
30+
* [Users, loans, fees and requests](#users-loans-fees-and-requests)
31+
* [Search](#search)
3032
* [Loans](#loans)
33+
* [Fees](#fees)
34+
* [Requests](#requests)
3135
* [Analytics reports](#analytics-reports)
3236
* [Column names](#column-names)
3337
* [Filters](#filters)
@@ -281,7 +285,7 @@ There is a special entrypoint to retrieve an item by barcode:
281285
$item = $alma->items->fromBarcode('92nf02526');
282286
```
283287

284-
## Users, loans and fees
288+
## Users, loans, fees and requests
285289

286290
**Note**: Editing is not yet implemented.
287291

@@ -321,6 +325,18 @@ foreach ($user->fees as $fee) {
321325
}
322326
```
323327

328+
### Requests
329+
330+
Example:
331+
332+
```php
333+
foreach ($user->requests as $request) {
334+
echo json_encode($request, JSON_PRETTY_PRINT);
335+
}
336+
```
337+
338+
Requests can also be retrieved from a `Bib` object or an `Item` object.
339+
324340
## Analytics reports
325341

326342
To retrieve the results from a single report:

spec/Bibs/BibSpec.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Scriptotek\Alma\Bibs\Holdings;
1111
use Scriptotek\Alma\Client as AlmaClient;
1212
use Scriptotek\Alma\Exception\ResourceNotFound;
13+
use Scriptotek\Alma\Users\Requests;
1314
use Scriptotek\Marc\Record;
1415
use spec\Scriptotek\Alma\SpecHelper;
1516

@@ -94,4 +95,9 @@ public function it_catches_resource_not_found(AlmaClient $client)
9495

9596
$this->exists()->shouldBe(false);
9697
}
98+
99+
public function it_has_requests()
100+
{
101+
$this->requests->shouldHaveType(Requests::class);
102+
}
97103
}

spec/Bibs/ItemSpec.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Scriptotek\Alma\Bibs\ScanInResponse;
1111
use Scriptotek\Alma\Conf\Library;
1212
use Scriptotek\Alma\Users\Loan;
13+
use Scriptotek\Alma\Users\Requests;
1314
use Scriptotek\Alma\Users\User;
1415
use spec\Scriptotek\Alma\SpecHelper;
1516

@@ -79,4 +80,9 @@ function it_can_be_scanned_in(AlmaClient $client, Library $library)
7980
$this->scanIn($library)
8081
->shouldHaveType(ScanInResponse::class);
8182
}
83+
84+
public function it_has_requests()
85+
{
86+
$this->requests->shouldHaveType(Requests::class);
87+
}
8288
}

spec/Users/RequestSpec.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace spec\Scriptotek\Alma\Users;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Prophecy\Argument;
7+
use Scriptotek\Alma\Client as AlmaClient;
8+
use Scriptotek\Alma\Users\Request;
9+
use Scriptotek\Alma\Users\User;
10+
11+
class RequestSpec extends ObjectBehavior
12+
{
13+
public function let(AlmaClient $client, User $user)
14+
{
15+
$this->beConstructedWith($client, $user, '123');
16+
}
17+
18+
function it_is_initializable()
19+
{
20+
$this->shouldHaveType(Request::class);
21+
}
22+
}

spec/Users/RequestsSpec.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace spec\Scriptotek\Alma\Users;
4+
5+
use Scriptotek\Alma\Client as AlmaClient;
6+
use Scriptotek\Alma\Users\Requests;
7+
use PhpSpec\ObjectBehavior;
8+
use Prophecy\Argument;
9+
use spec\Scriptotek\Alma\SpecHelper;
10+
11+
class RequestsSpec extends ObjectBehavior
12+
{
13+
public function let(AlmaClient $client)
14+
{
15+
$url = '/bibs/1/holdings/2/items/3/requests';
16+
$this->beConstructedWith($client, $url);
17+
}
18+
19+
public function it_is_countable(AlmaClient $client)
20+
{
21+
$client->getJSON('/bibs/1/holdings/2/items/3/requests')
22+
->shouldBeCalled()
23+
->willReturn(SpecHelper::getDummyData('item_requests_response.json'));
24+
25+
$this->shouldHaveCount(1);
26+
}
27+
28+
29+
function it_is_initializable()
30+
{
31+
$this->shouldHaveType(Requests::class);
32+
}
33+
}

spec/Users/UserSpec.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Scriptotek\Alma\Client as AlmaClient;
77
use Scriptotek\Alma\Users\Fees;
88
use Scriptotek\Alma\Users\Loans;
9+
use Scriptotek\Alma\Users\Requests;
910
use Scriptotek\Alma\Users\User;
1011
use spec\Scriptotek\Alma\SpecHelper;
1112

@@ -65,4 +66,9 @@ function it_has_fees(AlmaClient $client)
6566
SpecHelper::expectNoRequests($client);
6667
$this->fees->shouldHaveType(Fees::class);
6768
}
69+
70+
public function it_has_requests()
71+
{
72+
$this->requests->shouldHaveType(Requests::class);
73+
}
6874
}

spec/data/item_requests_response.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"total_record_count": 1,
3+
"user_request": [
4+
{
5+
"author": "Osipov, Andrey V.",
6+
"barcode": null,
7+
"comment": null,
8+
"description": null,
9+
"material_type": {
10+
"desc": null,
11+
"value": null
12+
},
13+
"mms_id": "999919897211902204",
14+
"pickup_location": "UiO Realfagsbiblioteket",
15+
"pickup_location_library": "1030310",
16+
"pickup_location_type": "LIBRARY",
17+
"place_in_queue": 1,
18+
"request_date": "2018-07-31Z",
19+
"request_id": "1403795240001204",
20+
"request_status": "NOT_STARTED",
21+
"request_sub_type": {
22+
"desc": "Patron physical item request",
23+
"value": "PATRON_PHYSICAL"
24+
},
25+
"request_type": "HOLD",
26+
"title": "Modern electromagnetic scattering theory with applications Andrey V. Osipov, Sergei A. Tretyakov",
27+
"user_primary_id": "Some User"
28+
}
29+
]
30+
}

src/Bibs/Bib.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Scriptotek\Alma\Client;
77
use Scriptotek\Alma\Exception\NoLinkedNetworkZoneRecordException;
88
use Scriptotek\Alma\Model\LazyResource;
9+
use Scriptotek\Alma\Users\Requests;
910
use Scriptotek\Marc\Record as MarcRecord;
1011
use Scriptotek\Sru\Record as SruRecord;
1112

@@ -23,11 +24,15 @@ class Bib extends LazyResource
2324
/* @var MarcRecord */
2425
protected $_marc;
2526

27+
/** @var Requests */
28+
public $requests;
29+
2630
public function __construct(Client $client = null, $mms_id = null)
2731
{
2832
parent::__construct($client);
2933
$this->mms_id = $mms_id;
3034
$this->holdings = Holdings::make($this->client, $this);
35+
$this->requests = Requests::make($this->client, $this->url('/requests'));
3136
}
3237

3338
/**

src/Bibs/Item.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Scriptotek\Alma\Conf\Library;
77
use Scriptotek\Alma\Model\LazyResource;
88
use Scriptotek\Alma\Users\Loan;
9+
use Scriptotek\Alma\Users\Requests;
910
use Scriptotek\Alma\Users\User;
1011

1112
class Item extends LazyResource
@@ -16,8 +17,11 @@ class Item extends LazyResource
1617
/** @var Holding */
1718
public $holding;
1819

20+
/** @var Requests */
21+
public $requests;
22+
1923
/** @var string */
20-
protected $item_id;
24+
public $item_id;
2125

2226
/**
2327
* Item constructor.
@@ -33,6 +37,7 @@ public function __construct(Client $client, Bib $bib, Holding $holding, $item_id
3337
$this->bib = $bib;
3438
$this->holding = $holding;
3539
$this->item_id = $item_id;
40+
$this->requests = Requests::make($this->client, $this->url('/requests'));
3641
}
3742

3843
/**

0 commit comments

Comments
 (0)