CVS edit link for Matthew Davidson
I am currently creating a website to facilitate a local "virtual library". As part of this I want to be able to pull book and author metadata from http://openlibrary.org. For this purpose I have written a set of simple wrapper functions to make it easy to use the Open Library Restful API (http://openlibrary.org/dev/docs/restful_api) in Drupal. Simple though it is, it's probably the most generally useful code I've ever produced for Drupal, so it seemed worthwhile making the effort to make it a public project.At the moment the API module enables developers to use all of the Open Library RESTful API, with the exception of the Save and Login calls (http://openlibrary.org/dev/docs/restful_api#save). These will be implemented in future, but as Save is currently regarded as an internal API, only functional from the Open Library localhost, and Login has no particular purpose except in the context of save, this is a low priority. I understand the Open Library developers are considering extending the API to securely allow remote saving.
The module caches retrieved data and cover images to be kind to the Open Library. At the moment the cache duration is set to one week, but in future versions this will be configurable.
In addition to the API, I've provided a set of theme functions, which will probably be sufficient for many developers to achieve what they want without having to use the lower level API functions or learn how Open Library RESTful API requests work in detail. The "block" display modes for Open Library book and author metadata have template files for ease of overriding.
I've also included another two modules which serve as examples for other developers, and are also intrinsically somewhat useful. The most substantial of these is a CCK display formatter for field types provided by the ISBN Field module (http://drupal.org/project/isbn). The project page for ISBN Field encourages development of such modules, so I'm confident I'm not treading on anybody's toes there.
The other "bonus" module is an input filter to insert book metadata into text fields. By itself this is a duplication of the Book Post module (http://drupal.org/project/bookpost), but the primary motivation for writing it was to show that project how to integrate their module with the Open Library API module to reduce the amount of code they need to maintain. It's a throwaway module which I'm quite happy to throw away should anybody object to it.
I've run all the code through the coder module, and have endeavoured to Doxygen comment at least all the functions intended for use by other developers. You can download the code at http://library.ourcoffs.org.au/code/openlibrary and for (ugly unstyled) examples of the output check out http://library.ourcoffs.org.au/node/2 and http://library.ourcoffs.org.au/code/examples/openlibrary-input-filter
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | openlibrary-6.x-0.3.tar_.gz | 7.31 KB | Matthew Davidson |
| #6 | openlibrary-6.x-0.2.tar_.gz | 7.3 KB | Matthew Davidson |
| #1 | openlibrary-6.x-0.1.tar_.gz | 13.89 KB | Matthew Davidson |
Comments
Comment #1
Matthew Davidson commentedHere's the code.
Comment #2
dawehnerJust one note.
Should be
So you can override theme_image in your template.php.
But the rest looks quite good.
Comment #3
avpaderno@dereine: If the OP is supposed to change the code, you should change the status of the issue.
Comment #4
avpadernoUse the Drupal string functions, when available.
In such cases, use a placeholder.
That information is added by the packaging script; remove it from the .info file.
The instruction will never find the file you are trying to include.
It is better to put
hook_theme()into the module, and remove the instruction to unconditionally include the other file; there is a way to instruct Drupal about which file the theme functions are.hook_theme(), and the actual parameters used by some theme functions; the match must be complete, not only for the parameter names.Comment #5
Matthew Davidson commentedD'oh! What an embarrassing one. Fixed (posted below). Thanks.
Comment #6
Matthew Davidson commented@KiamLaLuno Wow, thanks for the attention to detail. I had no idea how many obvious gaffs I'd made in a relatively small amount of code, and you've taught me a few things I didn't know. All these issues have been addressed now.
Comment #7
avpadernoThere is something to correct, and then we are ready.
Use the function placeholders.
Comment #8
Matthew Davidson commentedDone. Thanks again.
Comment #9
avpadernoComment #11
avpaderno