Skip to content

Commit bfd885d

Browse files
committed
Update readme and changelog
1 parent c7e51ce commit bfd885d

File tree

2 files changed

+77
-3
lines changed

2 files changed

+77
-3
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
88

99
(Nothing yet)
1010

11+
## [0.9.2] - 2020-05-14
12+
13+
### Added
14+
15+
- Added new options `maxAttemptsOnServerError` and `sleepTimeOnServerError`.
16+
17+
### Changed
18+
19+
- Updated the Laravel Service Provider to use existing PSR-17/18 interface bindings, if any.
20+
1121
## [0.9.1] - 2020-05-13
1222

1323
### Fixed

README.md

+67-3
Original file line numberDiff line numberDiff line change
@@ -482,17 +482,39 @@ Note: As of 2018-10-13, there is a bug preventing you from retrieving more than
482482

483483
### Requested resources (pick from shelf)
484484

485-
````php
485+
```php
486486
$library = $alma->conf->libraries['LIBRARY_CODE'];
487487
$requests = $alma->taskLists->getRequestedResources($library, 'DEFAULT_CIRC_DESK', [
488488
'printed' => 'N',
489489
]);
490490
foreach ($requests as $request) {
491491
echo "- {$request->resource_metadata->title} {$request->resource_metadata->mms_id->value}\n";
492492
}
493-
````
493+
```
494+
495+
## Automatic retries on errors
496+
497+
If the client receives a 429 (rate limiting) response from Alma, it will sleep for a short time (0.5 seconds by default)
498+
and retry the request a configurable number of times (10 by default), before giving up and throwing a
499+
`Scriptotek\Alma\Exception\MaxNumberOfAttemptsExhausted`.
500+
Both the max number of attempts and the sleep time can be configured:
501+
502+
```php
503+
$client->maxAttempts = 5;
504+
$client->sleepTimeOnRetry = 3; // seconds
505+
```
494506

495-
## Laravel 5 integration
507+
If the client receives a 5XX server error, it will by default not retry the request, but this can be configured.
508+
This can be useful when retrieving large Analytics reports, which have a tendency to fail intermittently.
509+
510+
```php
511+
$client->maxAttemptsOnServerError = 10;
512+
$client->sleepTimeOnServerError = 10; // seconds
513+
```
514+
515+
When the number of retries have been exhausted, a `Scriptotek\Alma\Exception\RequestFailed` exception is thrown.
516+
517+
## Laravel integration
496518

497519
This project ships with an auto-discoverable service provider and facade. Run
498520

@@ -509,6 +531,48 @@ And the facade:
509531

510532
'Alma' => Scriptotek\Alma\Laravel\Facade::class,
511533

534+
### Customizing the HTTP client stack
535+
536+
If the Laravel [Service Container](https://laravel.com/docs/master/providers)
537+
contains a PSR-18 HTTP Client bound to `Psr\Http\Client\ClientInterface`,
538+
Alma Client will use that implementation instead of instantiating its own HTTP
539+
client.
540+
541+
Here's an example service provider that registers a HTTP client with some middleware
542+
from [php-http/client-common](http://docs.php-http.org/en/latest/plugins/introduction.html#install):
543+
544+
```php
545+
<?php
546+
547+
namespace App\Providers;
548+
549+
use Http\Client\Common\Plugin\ContentLengthPlugin;
550+
use Http\Client\Common\Plugin\ErrorPlugin;
551+
use Http\Client\Common\Plugin\RetryPlugin;
552+
use Http\Client\Common\PluginClient;
553+
use Http\Factory\Discovery\HttpClient;
554+
use Illuminate\Support\ServiceProvider;
555+
use Psr\Http\Client\ClientInterface;
556+
557+
class HttpServiceProvider extends ServiceProvider
558+
{
559+
public function register()
560+
{
561+
$this->app->singleton(ClientInterface::class, function($app) {
562+
return new PluginClient(
563+
HttpClient::client(),
564+
[
565+
new ContentLengthPlugin(),
566+
new RetryPlugin([
567+
'retries' => 10,
568+
]),
569+
new ErrorPlugin(),
570+
]
571+
);
572+
});
573+
}
574+
}
575+
```
512576

513577
## Future plans
514578

0 commit comments

Comments
 (0)