- Notifications
You must be signed in to change notification settings - Fork1
Library to retrieve data about books
License
MacFJA/BookRetriever
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Library to retrieve data about books
composer require macfja/book-retriever
To get information of a book on a specific provider:
$htmlGetter =new \MacFJA\BookRetriever\Helper\HtmlGetter();$isbnTool =new \Isbn\Isbn();$antoineOnline =new \MacFJA\BookRetriever\Provider\AntoineOnline($htmlGetter,$isbnTool);$books =$antoineOnline->searchIsbn('9782253006329');// $books contains a list of \MacFJA\BookRetriever\SearchResultInterface
To get information of a book with a configurable provider:
$providerConfiguration =...;// A class that implement \MacFJA\BookRetriever\ProviderConfigurationInterface$configurator =new \MacFJA\BookRetriever\ProviderConfigurator($providerConfiguration);$amazon =new \MacFJA\BookRetriever\Provider\Amazon();$configurator->configure($amazon);$books =$amazon->searchIsbn('9782253006329');// $books contains a list of \MacFJA\BookRetriever\SearchResultInterface
Using thePool
provider to request several providers:
$providerConfiguration =...;// A class that implement \MacFJA\BookRetriever\ProviderConfigurationInterface$configurator =new \MacFJA\BookRetriever\ProviderConfigurator($providerConfiguration);$htmlGetter =new \MacFJA\BookRetriever\Helper\HtmlGetter();$isbn =new \Isbn\Isbn();$opds =new \MacFJA\BookRetriever\Helper\OPDSParser();$sru =new \MacFJA\BookRetriever\Helper\SRUParser();$providers = [new \MacFJA\BookRetriever\Provider\AbeBooks($htmlGetter),new \MacFJA\BookRetriever\Provider\Amazon(),new \MacFJA\BookRetriever\Provider\AntoineOnline($htmlGetter,$isbn),new \MacFJA\BookRetriever\Provider\ArchiveOrg($opds),new \MacFJA\BookRetriever\Provider\LibraryHub($sru),new \MacFJA\BookRetriever\Provider\DigitEyes(),new \MacFJA\BookRetriever\Provider\Ebay()];array_walk($providers, [$configurator,'configure']);$pool =new \MacFJA\BookRetriever\Pool($providers,$providerConfiguration);$books =$pool->searchIsbn('9782253006329');// $books contains a list of \MacFJA\BookRetriever\SearchResultInterface
If you use an dependency injection library, lots of code can be remove. (see below for a Symfony example)
An example of integration in Symfony with configuration stored in database with Doctrine as ORM.
config/services.yaml
services:_instanceof:# services whose classes are instances of ProviderInterface will be tagged automaticallyMacFJA\BookRetriever\ProviderInterface:tags:['app.provider']MacFJA\BookRetriever\:resource:'../vendor/macfja/book-retriever/lib/'MacFJA\BookRetriever\Pool:arguments:$providers:!tagged_iterator app.providerMacFJA\BookRetriever\ProviderConfigurationInterface:'@App\Repository\ProviderConfigurationRepository'
src/Entity/ProviderConfiguration.php
<?phpnamespaceApp\Entity;useDoctrine\ORM\MappingasORM;/** @ORM\Entity(repositoryClass="App\Repository\ProviderConfigurationRepository") */class ProviderConfiguration{/** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */private$id;/** @ORM\Column(type="string", length=50) */private$provider;/** @ORM\Column(type="boolean") */private$active;/** @ORM\Column(type="json") */private$parameters = [];// All Getters/Setters// Removed in this example for readability}
src/Repository/ProviderConfigurationRepository.php
<?phpnamespaceApp\Repository;useApp\Entity\ProviderConfiguration;useDoctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;useDoctrine\Common\Persistence\ManagerRegistry;useMacFJA\BookRetriever\ProviderConfigurationInterface;useMacFJA\BookRetriever\ProviderInterface;class ProviderConfigurationRepositoryextends ServiceEntityRepositoryimplements ProviderConfigurationInterface{publicfunction__construct(ManagerRegistry$registry) {parent::__construct($registry, ProviderConfiguration::class); }publicfunctiongetParameters(ProviderInterface$provider):array {$configuration =$this->findOneBy(['provider' =>$provider->getCode()]);return$configuration !==null ?$configuration->getParameters() : []; }publicfunctionisActive(ProviderInterface$provider):bool {$configuration =$this->findOneBy(['provider' =>$provider->getCode()]);// not active by defaultreturn$configuration !==null ?$configuration->getActive() :false; }}
src/Controller/SomeController.php
<?phpnamespaceApp\Controller;useMacFJA\BookRetriever\Pool;useSymfony\Bundle\FrameworkBundle\Controller\AbstractController;useSymfony\Component\HttpFoundation\JsonResponse;useSymfony\Component\Routing\Annotation\Route;class SomeControllerextends AbstractController{/** @Route("/test") */publicfunctionindex(Pool$pool) {returnnewJsonResponse($pool->searchIsbn('9782253006329')); }}
There are currently20 built-in providers.You can findmore details here.
You can contribute to the library.To do so, you have Github issues to:
- ask your question
- notify any change in the providers
- suggest new provider
- request any change (typo, bad code, etc.)
- and much more...
You also have PR to:
- add a new provider
- suggest a correction
- and much more...
First clone the project (either this repository, or your fork),next run:
make install# Install project vendormake all# Run QA tools + tests suites + generate docs
When you done writing your code run the following command check if the quality meet defined rule and to format it:
make analyze# Run QA tools + tests suites
If you add unit tests you run the following to do the same on test suite code:
make analyze-tests# Run QA tools on tests suites
The MIT License (MIT). Please seeLicense File for more information.
About
Library to retrieve data about books
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.