Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add contact read/write contact info to Users #20

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 65 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ If the package doesn't fit your needs, you might take a look at the alternative
* [Listing jobs](#listing-jobs)
* [Retrieving information about a specific job](#retrieving-information-about-a-specific-job)
* [Submitting a job](#submitting-a-job)
* [Code Tables](#code-tables)
* [Getting a single code table](#getting-a-codetable)
* [Automatic retries on errors](#automatic-retries-on-errors)
* [Laravel integration](#laravel-integration)
* [Customizing the HTTP client stack](#customizing-the-http-client-stack)
Expand Down Expand Up @@ -329,7 +331,7 @@ foreach ($bib->representations as $rep) {

## Users, loans, fees and requests

**Note**: Editing is not yet implemented.
**Note**: Editing is not fully implemented.

### Search

Expand All @@ -341,6 +343,54 @@ foreach ($alma->users->search('last_name~Heggø AND first_name~Dan') as $user) {
}
```

### Contact Info Updates

#### Update an address

Example:

```php
$uerr = $alma->users->get('EXTID_123456');
$user->contactInfo->unsetPreferredAddress();
$addresses = $user->contactInfo->getAddresses();
$campusBox = 'Box 876';
$changed = false;
foreach ($addresses as $address) {
if ($address->address_type[0]->value === 'school') {
$address->line1 = $campusBox;
$address->preferred = true;
$changed = true;
break;
}
}
if (!$changed) {
$new = json_decode('{ "preferred": true, "segment_type": "Internal", "line1": "My University", "line2": ".$campusBox.", "city": "Scottsdale", "state_province": "AZ", "postal_code": "85054", "country": { "value": "USA" }, "address_note": "string", "start_date": "2020-07-20", "end_date": "2021-07-20", "address_type": [ { "value": "school" } ] }');
$user->contactInfo->addAddress($new);
}
$user->save();
```

#### Add an SMS number

Example:

```php
$user = $alma->users->get('EXTID_123456');
$user->contactInfo->setSmsSNumber('18005882300');
$user->save();
```

#### Change an email

Example:

```php
$user = $alma->users->get('EXTID_123456');
$user->contactInfo->removeEmail('[email protected]');
$user->contactInfo->addEmail('[email protected]');
$user->save();
```

### Loans

Example:
Expand Down Expand Up @@ -530,6 +580,20 @@ $job = $alma->jobs['M43'];
$instance = $alma->jobs['M43']->submit();
```

## Code Tables

### Getting a Code Table

To fetch a code table

```php
$ct = $alma->codetables->get('systemJobStatus');
echo "Rows for ".$ct->sub_system->value."'s ".$ct->name."\n";
foreach ($ct->row as $row) {
echo "code: ".$row->code.", description: ".$row->description."\n";
}
```

## Automatic retries on errors

If the client receives a 429 (rate limiting) response from Alma, it will sleep for a short time (0.5 seconds by default)
Expand Down
47 changes: 47 additions & 0 deletions spec/Conf/CodeTableSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace spec\Scriptotek\Alma\CodeTable;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Scriptotek\Alma\Conf\CodeTable;
use Scriptotek\Alma\Conf\CodeTables;
use Scriptotek\Alma\Client as AlmaClient;
use Scriptotek\Alma\Exception\ResourceNotFound;
use spec\Scriptotek\Alma\SpecHelper;

class CodeTableSpec extends ObjectBehavior
{
public function let(AlmaClient $client)
{
$this->beConstructedWith($client, 'systemJobStatus');
}

protected function expectRequest($client)
{
$client->getXML('/conf/code-table/systemJobStatus')
->shouldBeCalled()
->willReturn(SpecHelper::getDummyData('codetable_response.json'));
}

public function it_is_lazy(AlmaClient $client)
{
SpecHelper::expectNoRequests($client);
$this->shouldHaveType(CodeTable::class);
}

public function it_fetches_record_data_when_needed(AlmaClient $client)
{
$this->expectRequest($client);

$this->name->('systemJobStatus');
$this->subSystem->value->shouldBe('INFRA');
}

public function it_can_exist(AlmaClient $client)
{
$this->expectRequest($client);

$this->exists()->shouldBe(true);
}
}
40 changes: 40 additions & 0 deletions spec/Conf/CodeTablesSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace spec\Scriptotek\Alma\CodeTables;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Scriptotek\Alma\Conf\CodeTable;
use Scriptotek\Alma\Client as AlmaClient;
use spec\Scriptotek\Alma\SpecHelper;

class CodeTablesSpec extends ObjectBehavior
{
public function let(AlmaClient $client)
{
$this->beConstructedWith($client);
}

public function it_provides_a_lazy_interface_to_codetable_objects(AlmaClient $client)
{
SpecHelper::expectNoRequests($client);

$ctid = 'myCodeTable'; // str_random();
$bib = $this->get($ctid);

$bib->shouldHaveType(CodeTable::class);
$bib->code->shouldBe($ctid);
}

public function it_provides_a_lazy_array_interface_to_codetable_objects(AlmaClient $client)
{
SpecHelper::expectNoRequests($client);

$ctid = 'myCodeTable'; // str_random();
$ct = $this[$ctid];

$ct->shouldHaveType(CodeTable::class);
$ct->code->shouldBe($ctid);
}

}
118 changes: 111 additions & 7 deletions spec/Users/UserSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,129 @@ public function it_has_requests()

public function it_has_sms()
{
$this->getSmsNumber()->shouldBe('87654321');
$this->contactInfo->getSmsNumber()->phone_number->shouldBe('87654321');
}

public function it_can_change_sms()
{
$this->setSmsNumber('12345678');
$this->getSmsNumber()->shouldBe('12345678');
$this->contactInfo->setSmsNumber('12345678');
$this->contactInfo->getSmsNumber()->phone_number->shouldBe('12345678');
}

public function it_can_add_sms()
{
$this->setSmsNumber('9999999');
$this->getSmsNumber()->shouldBe('9999999');
$this->contactInfo->setSmsNumber('9999999');
$this->contactInfo->getSmsNumber()->phone_number->shouldBe('9999999');
}

public function it_can_remove_sms()
{
$this->unsetSmsNumber();
$this->getSmsNumber()->shouldBe(null);
$this->contactInfo->unsetSmsNumber();
$this->contactInfo->getSmsNumber()->shouldBe(null);
}

public function it_can_add_email()
{
$this->contactInfo->addEmail('[email protected]', 'work', true);
$this->contactInfo->getEmail()->email_address->shouldBe('[email protected]');
}

public function it_can_unset_email()
{
$this->contactInfo->unsetEmail();
$this->contactInfo->getEmail()->shouldBe(null);
}

public function it_can_remove_email()
{
$this->contactInfo->removeEmail('[email protected]');
$this->contactInfo->allEmails()->shouldBe([]);
}

public function it_can_add_address()
{
$this->contactInfo->addAddress([
'line1' => '123 Something Blvd.',
'city' => 'Somewhere',
'state_province' => 'IL',
'postal_code' => '12345',
'country' => 'USA',
'address_type' => 'home'
])->shouldBeAnInstanceOf('Scriptotek\Alma\Users\Address');
$this->contactInfo->address[1]->shouldBeLike((object) [
'line1' => '123 Something Blvd.',
'city' => 'Somewhere',
'state_province' => 'IL',
'postal_code' => '12345',
'country' => (object) ['value' => 'USA'],
'address_type' => [(object) ['value' => 'home']]
]);
}

public function it_can_remove_address()
{
$address = $this->contactInfo->addresses[0];
$this->contactInfo->removeAddress($address);
$this->contactInfo->addresses->shouldBe([]);
}

public function it_can_set_preferred_address()
{
$address = $this->contactInfo->addresses[0];
$address->preferred = true;
$address->preferred->shouldBe(true);
$address->preferred = false;
$address->preferred->shouldBe(false);
}

public function it_can_unset_preferred_address()
{
$this->contactInfo->unsetPreferredAddress();
$this->contactInfo->getPreferredAddress()->shouldBe(null);
}

public function it_can_set_address_type()
{
$address = $this->contactInfo->addresses[0];
$address->setAddressType('work', 'Work');
$address->data->address_type[0]->shouldBeLike((object)[
'value' => 'work',
'desc' => 'Work'
]);
$address->address_type = 'home';
$address->data->address_type[0]->shouldBeLike((object)[
'value' => 'home'
]);
}

public function it_can_add_phone_number()
{
$this->contactInfo->addPhone('8675309', 'home', true);
$this->contactInfo->getPreferredPhone()->phone_number->shouldBe('8675309');
}

public function it_can_remove_phone_number()
{
$this->contactInfo->removePhone('12345678');
$this->contactInfo->getPreferredPhone()->shouldBe(null);
}

public function it_can_set_preferred_phone()
{
$this->contactInfo->setPreferredPhone('87654321');
$this->contactInfo->getPreferredPhone()->phone_number->shouldBe('87654321');
}

public function it_can_unset_preferred_phone()
{
$this->contactInfo->unsetPreferredPhone();
$this->contactInfo->getPreferredPhone()->shouldBe(null);
}

public function it_can_get_all_phone_numbers()
{
$phones = $this->contactInfo->allPhones();
$phones[0]->phone_number->shouldBe('12345678');
$phones[1]->phone_number->shouldBe('87654321');
}
}
Loading