Skip to content
Snippets Groups Projects
Commit dd6353b4 authored by Gregor Gawol's avatar Gregor Gawol
Browse files

added client into module

parent 98b73d26
Branches
Tags
No related merge requests found
Pipeline #1783 passed with stage
in 21 seconds
{
"name": "finc/boss-module",
"description": "Module for BOSS Client",
"description": "Module for BOSS Webservice",
"license": "GPL-2.0",
"authors": [
{
......@@ -10,8 +10,13 @@
],
"require": {
"php": ">=7.1",
"finc/boss-client": "dev-master",
"finc/vufindhttp-psrcompat": "dev-master"
"finc/vufindhttp-psrcompat": "dev-master",
"finc/vufindresolver-libmapper": "dev-master",
"psr/http-client": "^1.0",
"guzzlehttp/psr7": "^1.4",
"ext-json": "*",
"symfony/serializer": "^3.4",
"symfony/property-info": "^3.4"
},
"autoload": {
"psr-4": {
......@@ -29,7 +34,7 @@
"extra": {
"vufind": {
"themes": {
"res\theme": ".boss"
"res\theme": "boss"
}
}
}
......
<?php
/**
* Copyright (C) Leipzig University Library 2019.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* @author Gregor Gawol <gawol@ub.uni-leipzig.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2
*/
namespace finc\Boss\Client;
use Doctrine\Common\Annotations\AnnotationReader;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Uri;
use Psr\Http\Client\ClientInterface;
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
/**
* Class Client
*
* @package finc\Boss\Client
*/
class Client
{
protected const BOSS_URL = 'https://fernleihe.boss.bsz-bw.de/Holding/Query';
protected $baseUrl;
/**
* @var ClientInterface
*/
protected $httpClient;
/**
* Client constructor.
*
* @param ClientInterface $httpClient
*/
public function __construct(ClientInterface $httpClient)
{
$this->httpClient = $httpClient;
$this->baseUrl = new Uri(static::BOSS_URL);
}
/**
* @param $isxns
* @param $network
* @return array
* @throws ClientException
* @throws \Psr\Http\Client\ClientExceptionInterface
*/
public function getRequestISBN($isxns, $network)
{
$retval = [];
foreach ($isxns as $isxn) {
$uri = $this->baseUrl->withQuery("isxn[]=$isxn&network=$network");
$request = new Request('GET', $uri);
$response = $this->httpClient->sendRequest($request);
if ($response->getStatusCode() == "200") {
$data = $this->lookupData($response);
if (!empty($data->getHoldings())) {
$retval['data'] = $data->getHoldings();
$retval['param'] = $isxn;
return $retval;
}
}
}
return $retval;
}
/**
* @param $zdb
* @param $network
* @return array|void
* @throws ClientException
* @throws \Psr\Http\Client\ClientExceptionInterface
*/
public function getRequestZDB($zdb, $network)
{
$retval = [];
$uri = $this->baseUrl->withQuery("zdb=$zdb&network=$network");
$request = new Request('GET', $uri);
$response = $this->httpClient->sendRequest($request);
if ($response->getStatusCode() == "200") {
$retval['data'] = $this->lookupData($response)->getHoldings();
$retval['param'] = $zdb;
return $retval;
}
return $retval;
}
/**
* @param $author
* @param $title
* @param $year
* @param $network
* @return array
* @throws ClientException
* @throws \Psr\Http\Client\ClientExceptionInterface
*/
public function getRequestQuery($author, $title, $year, $network)
{
$uri = $this->baseUrl->withQuery("author=$author&title=$title&year=$year&network=$network");
$request = new Request('GET', $uri);
$response = $this->httpClient->sendRequest($request);
if ($response->getStatusCode() == "200") {
$retval['data'] = $this->lookupData($response)->getHoldings();
$retval['param'] = '';
return $retval;
}
return [];
}
private function lookupData($response): Root
{
try {
$jsonEncoder = new JsonEncoder();
// TODO: caching data
// symfony/serializer suggests installing doctrine/cache (For using the default cached annotation reader and metadata cache.)
$objectNormalizers = new ObjectNormalizer(
// null,//new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader(null))),
// new CamelCaseToSnakeCaseNameConverter(),
// null,
// new ReflectionExtractor()
);
$serializer = new Serializer(
[
$objectNormalizers//,
// $attributesDenormalizer = new AttributesDenormalizer(),
// new ArrayDenormalizer(),
],
[
$jsonEncoder
]
);
// $attributesDenormalizer->setDenormalizer($serializer);
return $serializer->deserialize(
(string)$response->getBody(),
Root::class,
'json'
);
} catch (HttpClientException $ex) {
throw new ClientException($ex->getMessage(), $ex->getCode(), $ex);
}
}
}
<?php
/**
* Copyright (C) Leipzig University Library 2019.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* @author Gregor Gawol <gawol@ub.uni-leipzig.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2
*/
namespace finc\Boss\Client;
class ClientException extends \Exception
{
}
<?php
/**
* Copyright (C) 2018 Leipzig University Library
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* @author Gregor Gawol <gawol@ub.uni-leipzig.de>
* @author Sebastian Kehr <kehr@ub.uni-leipzig.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2
*/
namespace finc\Boss\Client;
class Holding
{
/**
* @var string
*/
protected $isil;
/**
* @var string
*/
protected $callnumber;
/**
* @var string
*/
protected $issue;
/**
* @return string
*/
public function getIsil(): string
{
return $this->isil;
}
/**
* @param string $isil
*/
public function setIsil(string $isil): void
{
$this->isil = $isil;
}
/**
* @return string
*/
public function getCallnumber(): string
{
return $this->callnumber;
}
/**
* @param string $callnumber
*/
public function setCallnumber(string $callnumber): void
{
$this->callnumber = $callnumber;
}
/**
* @return string
*/
public function getIssue(): string
{
return $this->issue;
}
/**
* @param string $issue
*/
public function setIssue(string $issue): void
{
$this->issue = $issue;
}
}
<?php
/**
* Copyright (C) 2018 Leipzig University Library
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* @author Gregor Gawol <gawol@ub.uni-leipzig.de>
* @author Sebastian Kehr <kehr@ub.uni-leipzig.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2
*/
namespace finc\Boss\Client;
class Root
{
/**
* @var Holding[]
*/
protected $holdings = [];
/**
* @var int
*/
protected $numppn;
/**
* @var int
*/
protected $numfound;
/**
* @param Holding $holding
*/
public function addHolding(Holding $holding): void
{
$this->holdings[] = $holding;
}
/**
* @return Holding[]
*/
public function getHoldings(): array
{
return $this->holdings;
}
/**
* @param Holding[] $holdings
*/
public function setHoldings(array $holdings): void
{
$this->holdings = $holdings;
}
/**
* @return int
*/
public function getNumppn(): int
{
return $this->numppn;
}
/**
* @param int $numppn
*/
public function setNumppn(int $numppn): void
{
$this->numppn = $numppn;
}
/**
* @return int
*/
public function getNumfound(): int
{
return $this->numfound;
}
/**
* @param int $numfound
*/
public function setNumfound(int $numfound): void
{
$this->numfound = $numfound;
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment