The Gitlab instance will be restarted on Monday April 28th at 2AM. There will be a short interruption of service.

Skip to content
Snippets Groups Projects
Commit f1dcfc18 authored by Jochen Lienhard's avatar Jochen Lienhard Committed by Demian Katz
Browse files

Implementation of cover driver for Buchhandel.de

parent 52533a6b
No related merge requests found
...@@ -572,7 +572,7 @@ database = mysql://root@localhost/vufind ...@@ -572,7 +572,7 @@ database = mysql://root@localhost/vufind
;coversize = false ;coversize = false
; You can select Syndetics, LibraryThing, Summon, Amazon, Booksite, OpenLibrary, ; You can select Syndetics, LibraryThing, Summon, Amazon, Booksite, OpenLibrary,
; Contentcafe and/or Google Books. ; Contentcafe, Buchhandel.de and/or Google Books.
; Note: Summon service takes a Serials Solutions client key, NOT Summon API key! ; Note: Summon service takes a Serials Solutions client key, NOT Summon API key!
;coverimages = Syndetics:MySyndeticsId,Amazon:MyAccessKeyId,Booksite,LibraryThing:MyLibraryThingId,Google,OpenLibrary,Summon:MySerialsSolutionsClientKey,Contentcafe:MyContentCafeID ;coverimages = Syndetics:MySyndeticsId,Amazon:MyAccessKeyId,Booksite,LibraryThing:MyLibraryThingId,Google,OpenLibrary,Summon:MySerialsSolutionsClientKey,Contentcafe:MyContentCafeID
...@@ -641,6 +641,14 @@ authors = Wikipedia ...@@ -641,6 +641,14 @@ authors = Wikipedia
; You can select from Google, OpenLibrary, HathiTrust. You should consult ; You can select from Google, OpenLibrary, HathiTrust. You should consult
; http://code.google.com/apis/books/branding.html before using Google Book Search. ; http://code.google.com/apis/books/branding.html before using Google Book Search.
; previews = Google,OpenLibrary,HathiTrust ; previews = Google,OpenLibrary,HathiTrust
; This section is needed for Buchhandel.de cover loading. You need an authentication
; token. It may also be necessary to customize your templates in order to comply with
; terms of service; please look at http://info.buchhandel.de/handbuch_links for
; details before turning this on.
[Buchhandel]
url = "https://api.vlb.de/api/v1/cover/"
; token = "XXXXXX-XXXX-XXXXX-XXXXXXXXXXXX"
; Possible HathiRights options = pd,ic,op,orph,und,umall,ic-world,nobody,pdus,cc-by,cc-by-nd, ; Possible HathiRights options = pd,ic,op,orph,und,umall,ic-world,nobody,pdus,cc-by,cc-by-nd,
; cc-by-nc-nd,cc-by-nc,cc-by-nc-sa,cc-by-sa,orphcand,cc-zero,und-world,icus ; cc-by-nc-nd,cc-by-nc,cc-by-nc-sa,cc-by-sa,orphcand,cc-zero,und-world,icus
......
...@@ -306,6 +306,7 @@ $config = [ ...@@ -306,6 +306,7 @@ $config = [
'factories' => [ 'factories' => [
'amazon' => 'VuFind\Content\Covers\Factory::getAmazon', 'amazon' => 'VuFind\Content\Covers\Factory::getAmazon',
'booksite' => 'VuFind\Content\Covers\Factory::getBooksite', 'booksite' => 'VuFind\Content\Covers\Factory::getBooksite',
'buchhandel' => 'VuFind\Content\Covers\Factory::getBuchhandel',
'contentcafe' => 'VuFind\Content\Covers\Factory::getContentCafe', 'contentcafe' => 'VuFind\Content\Covers\Factory::getContentCafe',
'syndetics' => 'VuFind\Content\Covers\Factory::getSyndetics', 'syndetics' => 'VuFind\Content\Covers\Factory::getSyndetics',
], ],
......
<?php
/**
* Buchhandel cover content loader.
*
* PHP version 5
*
* Copyright (C) Villanova University 2010.
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @category VuFind2
* @package Content
* @author Demian Katz <demian.katz@villanova.edu>
* @author Jochen Lienhard <lienhard@ub.uni-freiburg.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/vufind2:developer_manual Wiki
*/
namespace VuFind\Content\Covers;
/**
* Buchhandel cover content loader.
*
* @category VuFind2
* @package Content
* @author Demian Katz <demian.katz@villanova.edu>
* @author Jochen Lienhard <lienhard@ub.uni-freiburg.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/vufind2:developer_manual Wiki
*/
class Buchhandel extends \VuFind\Content\AbstractCover
{
/**
* Base URL for Buchhandel
*
* @var string
*/
protected $url;
/**
* API token for Buchhandel
*
* @var string
*/
protected $apiToken;
/**
* Constructor
*
* @param string $url Base URL for Buchhandel
* @param string $apiToken API token for Buchhandel
*/
public function __construct($url, $apiToken)
{
$this->url = $url;
$this->apiToken = $apiToken;
$this->supportsIsbn = true;
$this->cacheAllowed = false;
}
/**
* Get image URL for a particular API token and set of IDs (or false if invalid).
*
* @param string $key API key
* @param string $size Size of image to load (small/medium/large)
* @param array $ids Associative array of identifiers (keys may include 'isbn'
* pointing to an ISBN object and 'issn' pointing to a string)
*
* @return string|bool
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function getUrl($key, $size, $ids)
{
if (!isset($ids['isbn'])) {
return false;
}
$isbn = $ids['isbn']->get13();
switch ($size) {
case 'small':
case 'medium':
case 'large':
$lsize = substr($size, 0, 1);
break;
default:
$lsize = "s";
break;
}
return "{$this->url}{$isbn}/{$lsize}?access_token={$this->apiToken}";
}
}
...@@ -76,6 +76,24 @@ class Factory ...@@ -76,6 +76,24 @@ class Factory
return new Booksite($url, $config->Booksite->key); return new Booksite($url, $config->Booksite->key);
} }
/**
* Create Buchhandel.de loader
*
* @param ServiceManager $sm Service manager
*
* @return mixed
*/
public static function getBuchhandel(ServiceManager $sm)
{
$config = $sm->getServiceLocator()->get('VuFind\Config')->get('config');
$url = isset($config->Buchhandel->url)
? trim($config->Buchhandel->url, '/').'/' : 'https://api.vlb.de/api/v1/cover/';
if (!isset($config->Buchhandel->token)) {
throw new \Exception("Buchhandel.de 'token' not set in VuFind config");
}
return new Buchhandel($url, $config->Buchhandel->token);
}
/** /**
* Create a ContentCafe loader * Create a ContentCafe loader
* *
......
<?php
/**
* Unit tests for Buchhandel cover loader.
*
* PHP version 5
*
* Copyright (C) Villanova University 2010.
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @category VuFind2
* @package Search
* @author Demian Katz <demian.katz@villanova.edu>
* @author Jochen Lienhard <lienhard@ub.uni-freiburg.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org
*/
namespace VuFindTest\Content\Covers;
use VuFindCode\ISBN, VuFind\Content\Covers\Buchhandel;
/**
* Unit tests for Booksite cover loader.
*
* @category VuFind2
* @package Search
* @author Demian Katz <demian.katz@villanova.edu>
* @author Jochen Lienhard <lienhard@ub.uni-freiburg.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org
*/
class BuchhandelTest extends \PHPUnit_Framework_TestCase
{
/**
* Test cover loading
*
* @return void
*/
public function testValidCoverLoading()
{
$loader = new Buchhandel('http://base/', 'mytoken');
$this->assertEquals(
'http://base/9780739313121/s?access_token=mytoken',
$loader->getUrl(
'mytoken', 'small', ['isbn' => new ISBN('0739313126')]
)
);
}
/**
* Test missing ISBN
*
* @return void
*/
public function testMissingIsbn()
{
$loader = new Buchhandel('http://base', 'mytoken');
$this->assertEquals(false, $loader->getUrl('mytoken', 'small', []));
}
}
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