1.0.0 • Published 4 years ago

sra-exlibris v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

SRA-Exlibris-Request

This module is part of the Bond University Centre for Research in Evidence-Based Practice Systematic Review Assistant suite of tools.

This module forms the reference request tool.

var exlibrisRequest = require('sra-exlibis-request');

new sraExlibrisRequest()
	.set({
		exlibris: {
			apiKey: 'YOUR API KEY'
		},
		user: {
			email: 'someone@somewhere', // User making request
		},
	})
	.set('request.source', 'SRA') // Set some extra request fields
	.set('request.note', 'SRA')
	.set('validator', (ref, eref) => { // Custom validator code
		if (!ref.type) return 'No reference type specified';
		if (ref.type == 'book') {
			if (!eref.title) return 'Missing book title';
			if (!eref.journal) return 'Missing journal';
			eref.pickup_location = 'MAIN',
			eref.format = 'PHYSICAL';
			eref.citation_type = 'BK';
		}
		return true;
	})
	.requestAll(refs, function(err, res) { // Request a bunch of references (maybe use reflib - https://github.com/hash-bang/Reflib-Node - to read in a library?)
		expect(err).to.be.not.ok;
		done();
	})

See the testkits for more examples.

API

ExlibrisRequest (class)

The main ExlibrisRequest class is used to setup the instance with initial settings and provide an API.

Supported Settings:

SettingTypeDefaultDescription
exlibrisObjectSee belowSettings passed onto the Exlibris NPM module
exlibris.regionString"eu"What Exlibris region server the place the request with
exlibris.apiKeyStringnoneYour Exlibris API key
exlibris.resourceRequestRetryNumber10How many times to retry a single request if it fails
exlibris.resourceRequestRetryDelayFunctionSee codeHow to calculate how long to wait between requests. Default behaviour is to pick a random millisecond delay between 0 and 2000
exlibris.threadsNumber2How many requests to place simultaneously
userObjectSee belowInformation about the user to place the request against
user.emailStringnoneThe users email to link the request against
requestObject{}Additional fields to provide in the request
validatorFunction()=> trueValidator function used to verify that a reference can be submitted. Should return either a boolean or a string (error message). Note, this occurs AFTER the field translation stage, so the fields are Exlibris and NOT Reflib spec. If you are mutating the object, mutate the Exlibris object (eRef)
debugObjectSee belowDebug flags
debug.execRequestBooleanfalseWhether to actually place requests. User details and all other validation stages are applied except the final submission
debug.titleMangleStringtitle => titleHow to mutate the citation title before submission. Override this function to specify a prefix / suffix
cacheObjectSee belowCaching details, the cache is used only on this instance and can significantly speed up requests if working in batches
cache.enabledBooleantrueWhether to use caching
cache.cacheGetFunctionSee codeUses simple memory caching
cache.cacheSetFunctionSee codeUses simple memory caching

Notes:

  • The debug.execRequest flag is disabled by default. Set this to true to make the library submit requests, although you should test without this enabled first
  • All functions are chainable

ExlibrisRequest.set(config, value)

Used to quickly set one or more config values. See the main constructor for a list of settings.

ExlibrisRequest
	.set('key1', 'value1')
	.set('key2', 'value2')
	.set('key3.subKey1', 'value3')

ExlibrisRequest.set({
	key1: 'value1',
	key2: 'value2',
	key3: {
		subKey1: 'value3',
	},
})

ExlibrisRequest.request(ref, options, cb)

Make a citation request to Exlibris.

The reference should be in the reflib format.

Options can be specified to override the defaults. Callback is optional.

ExlibrisRequest.requestAll(refs, options, cb)

Similar to request() but places requests in batch.

See the request function for details.

Events

The ExlibrisRequest instance can also fire events.

EventParametersDescription
requestSucceed(ref, attempt)Fired when a request succeeded
requestRetry(ref, attempt, tryagainInTimeout)Fired when a request fails but will be retried
requestFailed(ref, attempts)Fired when a request failed after retrying
requestError(ref, err)Fired when a request is completely rejected by the server