Skip to content
bfontaine edited this page Jan 4, 2013 · 4 revisions

Configuration

Configuration variables can be set with api.set() function, unset with api.unset(), and got with api.getVar():

  • api.set( args ): args can be an object, a string (it sets the value to true), or a string and a value, e.g.:
api.set( "foo" ); // set 'foo' to true
api.set( "foo", 42 ); // set 'foo' to 42
api.set({ foo: 74 }); // set 'foo' to 74
  • api.unset( args ): args can be a string, or an array of string, e.g.:
api.unset( 'foo' ); // unset 'foo'
api.unset([ 'foo', 'bar' ]); // unset 'foo' & 'bar'
api.unset( 'foo', 'bar' ); // unset 'foo' & 'bar'
  • api.getVar( v ): v must be a string, e.g.:
api.set( 'bar', 789 );
api.getVar( 'bar' ); // 789

Currently only one value is supported:

  • cache (Boolean): if true, all entities will be cached, i.e. will not be fetched more than once.

Books

Get Books by their IBSN

Usage

api.getBookByISBN( opts )

opts is an object with the usual attributes:

  • query (String): The ISBN code
  • callback (Function): This function is called with the Book object, which have been fetched before
  • error (Function): Error callback

The function return the Book object. Since the fetching is asynchronous, the object may not have its attributes filled, so you should use the callback attribute to be sure.

Example

api.getBookByISBN({
    query: '9782212136081',  // this is the ISBN code
    callback: function( book ) {
        if ( !book.exists ) {
            console.log( "This book doesn’t exist :(");
        else {
            console.log( "The book’s title is: " + book.title );
        }
    }
});

Tips

  • api.getBookByISBN( '9782212136081' ) is a shortcut for api.getBookByISBN({ query: '9782212136081' }).

Search

Usage

api.search( opts )

opts is an object with the usual attributes:

  • query (String): The string query
  • callback (Function): This function is called with a BooksList object, which have been fetched before
  • error (Function): Error callback
  • limit (Number): The maximum number of books to retrieve (default: 20)
  • offset (Number): The list offset (default: 0)

Example

api.search({
    query: 'Foo',
    callback: function( books ) {
        var i = 0, len = books.length;
        console.log( len + ' book(s) found:');
        for (; i<len; i++) {
            console.log( '\t' + books[i].title );
        }
    }
});