2017 © Pedro PelĂĄez
 

library sru-client

Package for making Search/Retrieve via URL requests and parse the responses

image

scriptotek/sru-client

Package for making Search/Retrieve via URL requests and parse the responses

  • Monday, October 2, 2017
  • by danmichaelo
  • Repository
  • 5 Watchers
  • 10 Stars
  • 889 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 16 Versions
  • 37 % Grown

The README.md

Coverage Code Quality Latest Stable Version Total Downloads, (*1)

php-sru-client

Simple PHP package for making Search/Retrieve via URL (SRU) requests and returning QuiteSimpleXMLElement objects. The response object is an iterator, to support easy iteration over the results, abstracting away the process of making multiple requests., (*2)

If you prefer a simple text response, you might have a look at the php-sru-search package., (*3)

Install using Composer

Use Composer to install sru-client with a HTTP library such as Guzzle:, (*4)

composer require scriptotek/sru-client php-http/guzzle6-adapter http-interop/http-factory-guzzle

We use HTTP discovery to discover HTTP client and HTTP factory implementations, so Guzzle can be swapped with any other PSR-17/PSR-18-compatible library., (*5)

Configuring the client

require_once('vendor/autoload.php');
use Scriptotek\Sru\Client as SruClient;

$sru = new SruClient('http://bibsys-network.alma.exlibrisgroup.com/view/sru/47BIBSYS_NETWORK', [
    'schema' => 'marcxml',
    'version' => '1.2',
    'user-agent' => 'MyTool/0.1',
]);

Search and retrieve

To get all the records matching a given CQL query:, (*6)

$records = $sru->all('alma.title="Hello world"');
foreach ($records as $record) {
    echo "Got record " . $record->position . " of " . $records->numberOfRecords() . "\n";
    // processRecord($record->data);
}

where $record is an instance of Record and $record->data is an instance of QuiteSimpleXMLElement., (*7)

The all() method takes care of continuation for you under the hood for you; the Records generator continues to fetch records until the result set is depleted. A default batch size of 10 is used, but you can give any number supported by the server as a second argument to the all() method., (*8)

If you query for some identifier, you can use the convenience method first():, (*9)

$record = $sru->first('alma.isbn="0415919118"');

The result is a Record object, or null if not found., (*10)

Use explain to get information about servers

$urls = array(
    'http://sru.bibsys.no/search/biblio',
    'http://lx2.loc.gov:210/LCDB',
    'http://services.d-nb.de/sru/zdb',
    'http://api.libris.kb.se/sru/libris',
);

foreach ($urls as $url) {

    $sru = new SruClient($url, [
        'version' => '1.1',
        'user-agent' => 'MyTool/0.1'
    ]);

    try {
        $response = $sru->explain();
    } catch (\Scriptotek\Sru\Exceptions\SruErrorException $e) {
        print 'ERROR: ' . $e->getMessage() . "\n";
        continue;
    }

    printf("Host: %s:%d\n", $response->host, $response->port);
    printf("  Database: %s\n", $response->database->identifier);
    printf("  %s\n", $response->database->title);
    printf("  %s\n", $response->database->description);
    print "  Indexes:\n";
    foreach ($response->indexes as $idx) {
        printf("   - %s: %s\n", $idx->title, implode(' / ', $idx->maps));
    }

}

Laravel 5 integration

Add the service provider to the 'providers' array in config/app.php:, (*11)

Scriptotek\Sru\Providers\SruServiceProvider::class,

Optionally, add the facade to the 'aliases' array in the same file:, (*12)

'SruClient'      => Scriptotek\Sru\Facades\SruClient::class,

To create the configuration file config/sru.php:, (*13)

$ php artisan vendor:publish --provider="Scriptotek\Sru\Providers\SruServiceProvider"

The Versions

02/10 2017
29/06 2017

v0.5.0

0.5.0.0 http://github.com/scriptotek/sru-client

Package for making Search/Retrieve via URL requests and parse the responses

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dan Michael O. Heggø

sru

30/10 2016

v0.4.2

0.4.2.0 http://github.com/scriptotek/sru-client

Package for making Search/Retrieve via URL requests and parse the responses

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dan Michael O. Heggø

sru

21/08 2016

v0.4.1

0.4.1.0 http://github.com/scriptotek/sru-client

Package for making Search/Retrieve via URL requests and parse the responses

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dan Michael O. Heggø

sru

20/08 2016

v0.4.0

0.4.0.0 http://github.com/scriptotek/sru-client

Package for making Search/Retrieve via URL requests and parse the responses

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dan Michael O. Heggø

sru

12/06 2016

v0.3.2

0.3.2.0 http://github.com/scriptotek/sru-client

Package for making Search/Retrieve via URL requests and parse the responses

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dan Michael O. Heggø

sru

22/01 2016

v0.3.1

0.3.1.0 http://github.com/scriptotek/sru-client

Package for making Search/Retrieve via URL requests and parse the responses

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dan Michael O. Heggø

sru

22/01 2016

v0.3.0

0.3.0.0 http://github.com/scriptotek/sru-client

Package for making Search/Retrieve via URL requests and parse the responses

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dan Michael O. Heggø

sru

25/08 2015

v0.2.0

0.2.0.0 http://github.com/scriptotek/sru-client

Package for making Search/Retrieve via URL requests and parse the responses

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dan Michael O. Heggø

sru

06/08 2014

v0.1.2

0.1.2.0 http://github.com/scriptotek/sru-client

Package for making Search/Retrieve via URL requests and parse the responses

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dan Michael O. Heggø

sru

17/05 2014

v0.1.1

0.1.1.0 http://github.com/scriptotek/sru-client

Package for making Search/Retrieve via URL requests and parse the responses

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dan Michael O. Heggø

sru

26/04 2014

v0.1.0

0.1.0.0 http://github.com/scriptotek/sru-client

Package for making Search/Retrieve via URL requests and parse the responses

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dan Michael O. Heggø

sru