Giter VIP home page Giter VIP logo

trove-js's Introduction

trove-js

A JavaScript library to access the National Library of Australia's (NLA) Trove API.

The Trove website can be found at https://trove.nla.gov.au.

Trove's v2 API is documented here.

This library works with: https://api.trove.nla.gov.au/v2

A simple live search example is here.

If you just want to use the library in your webpage

  1. Get a Trove API key: see here
  2. Download dist/trove-api.js or dist/trove-api.min.js
  3. Include it in your web page
  4. Use it

Developing the library

Source files are in src, concatenated and minified distribution files are in dist.

You'll need npm, babel and webpack installed to generate the distribution files.

Clone this repository, and go to the directory created. Type:

npm install

This will install the dependencies for building and testing.

There are a number of npm scripts defined, but be aware that the unit tests will need a Trove API key in the __key_file__ file.

Task Description
build Check code style, package the library.
docs Generate html docs.
docs:md Generate markdown docs.
lint Check code style.
test Runs unit tests (you'll need an API key to run the tests).

To build the dist/trove-api.js after modifying a source file just type:

npm run build

which should check your files for code style and produce the concatenated file.

Getting an API key

You'll need to get an API key first, by signing up and requesting one. Instructions for doing so are found at Trove Help.

Both the unit tests and the demo page will load a key from the __key_file__ file. So if you want to run the tests or try out the demo page, put your key in this file (DON'T commit and push this change to GitHub).

Please comply with the conditions of use, an put "powered by trove" somewhere on your site.

Library initialisation

In your JavaScript, initialise the library first giving it your key:

Trove.init(your_key);

Asynchrony

Remember that each time you make a call for data, the data will not be available until the Trove servers respond. For example, if you were to write:

var article = new Trove.NewspaperArticle({
    init: 18342701
});
console.log(article.heading);

you would, more than likely, see 'undefined' at the console. For this reason, the API provides a parameter for a function to be called when the request completes:

var article = new Trove.NewspaperArticle({
    init: 18342701,
    done: function (a) {console.log(a.heading)};
});

You could also write:

function done_callback(a) {
    console.log(a.heading);
}

var article = new Trove.NewspaperArticle({
    init: 18342701,
    done: done_callback
});

to get the same result. The parameter to the called function is the object that has been updated by the request.

Examples and Documentation

Please see the wiki for examples

There are API docs here and you can build HTML API pages using npm run docs.

There is a simple search example at http://chrrrisw.github.io/trove-js/

trove-js's People

Contributors

chrrrisw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

trove-js's Issues

Common Work class

The Article, Collection, Book, Picture, Map and Music classes should all inherit from a common Work class.

Add build system

Add a build system to generate concatenated and minified versions of the library. The source code should be within the one namespace across multiple files.

Failure handling

JQuery doesn't call the fail callback for cross-domain jsonp requests.

Failure handling should therefore be removed from the library unless some other mechanism is used.

Consistent search limit handling

Passing limits into the search.query() method overwrites any existing limits. In particular, date limits are not handled well. Make consistent and easy interface for limit handling.

Add "supported indexes"

Search currently supports a string interface for "terms". Add support for boolean logic operators and other "supported indexes" such as:

creator:(Donald Norman)
subject:(cognitive psychology)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.