ISBNDBService is a PHP interface to the ISBNdb webservice. It gives complete access to the API that ISBNdb offers. Written using PHP5s OOP possibilities it is a clean and efficient library.
Robert van der Linde is a PHP software engineer at Sogeti Netherlands. As a Zend certified engineer with a keen interest in security he is the PHP foreman of Sogeti’s company wide security initiative (PaSS).
If you want to contact me, you are more than welcome to drop a line @ robert_AT_linde002_DOT_nl
The library is divided into 9 classes. Your main interaction will be with
You start by instantiating a new instance of the ISBNDBService using your API key as the constructor's argument. After you queried your instance using the search method it will return a ISBNDBPaginator instance which you can then query to retrieve the current ISBNDBCollection that holds the result.
The result will have specific properties pertaining to the specific result type (A book has a title, author has a name, etc)
It is advisable to extend the ISBNDBService class to create your own if you want to query the webservice with simple requests.
ISBNDBServices retrieves the XML response using a simple file_get_contents() call, which might give problems if you need to use a proxy or have file operations over HTTP disabled in your php.ini. To parse the XML it uses the DOMDocument classes, if you haven't enabled this module ISBNDBService will not work.
If you are passing an ISBN as an argument be sure to pass it as a string, contained in single or double quotes, passing an ISBN as an int can create strange behaviour when PHP tries to cast the int as a string. i.e: 05423042 can be interpreted as an octal number, which results in a cast to decimal 1451554.
<php
/**
* You are free to include each class file manually (be sure to first include ISBNDBResult before
* ISBNDBAuthor/Book/Category/Publisher/Subject) but it is usually easier to use an autoloader.
*/
function __autoload($className)
{
include('/path/to/ISBNDBService/'.$className.'.php');
}
/**
* Instantiate a new ISBNDBService instance
*/
$service = new ISBNDBService('MyKey');
/**
* Search the Books API using the ISBN with
* ISBN: 9781853267796.
* Return the detailed information for this book along with summary texts etc if available.
*/
$searchResults = $service->search(ISBNDBService::API_BOOKS,
ISBNDBService::SEARCH_TYPE_ISBN,
'9781853267796',
array(ISBNDBService::RESULT_TYPE_TEXTS, ISBNDBService::RESULT_TYPE_DETAILS));
/**
* Loop over the resulting pages
*/
foreach($searchResults as $page)
{
/**
* Loop over each result in the page
*/
foreach($page as $result)
{
/**
* print the title followed by a
and a newline.
*/
print $result->title.'
'.PHP_EOL;
}
}
// Prints "The Art of War/The Book Of Lord Shang<br />"
/**
* Or just show me the title for the first result
*/
print $searchResults->get(1)->get(0)->title.'
'.PHP_EOL;
// Prints "The Art of War/The Book Of Lord Shang<br />"
?>
You can get the latest sourcode here and the PHPDoc documentation can be found here.
The code is provided as is and should work without problems. However it does use file_get_contents() to retrieve the XML response from ISBNdb.org. This won't work if you've changed certain settings in your php.ini file or if you need to specify a proxy server.
If you need support, want to ask questions or just send a thank you note feel free to email me at robert_at_linde002_dot_nl. However, keep in mind that I built this as a little hobby library and am not on call 24/7, this requires you to send me chocolate and presents.
ISBNDBService is designed to be extended. For a basic customization you add your own methods that call the doRequest method
as you would ISBNDBService::search().
The standard way to interact with ISBNDBService is using the search() method. But this code is usually bulky and to abstract
(because ISBNDBService is designed to interact with all ISBNdb.org's possibilities). If you simply want to get book information from an ISBN
number you can subclass ISBNDBService to create custom methods that do just that.
<php
class SimpleISBNService extends ISBNDBService
{
/**
* Call the parent constructor
*/
public function __construct($accessKey)
{
parent::__construct($accessKey);
}
/**
* To perform the actual request call the doRequest method as you would
* the normal search function
*/
public function findByISBN($isbn)
{
return $this->doRequest(self::API_BOOKS,
self::SEARCH_TYPE_ISBN,
$isbn,
array(self::RESULT_TYPE_DETAILS));
}
public function findFirstByISBN($isbn)
{
$result = $this->findByISBN($isbn);
return $result->get(1)->get(0);
}
}
$service = new SimpleISBNService('MyKey');
$myBook = $service->findFirstByISBN('9781853267796');
?>
These references contain information about the different aspects involved in creating and using ISBNDBService