frick-sierra
Sierra API Interface
Last updated a month ago by mrwho .
Apache-2.0 · Original npm · Tarball · package.json
$ cnpm install frick-sierra 
SYNC missed versions from official npm registry.

Sierra API Client

Testing from the command line

Before you start

Install the dependencies

Once you cloned this repo run

npm i

This command will install the needed libraries.

Configuration

Copy config.tpl.yaml into config.yml. Fill in token and password as username and password

Testing a request

Use the request.yml to test making requests for a list of bibrecords and getting back a spreadsheet with the values.

You should be able to run npm start and have the cli run the request and download the information.

As a library

Authentication flow

Authentication can be a one shot authentication or can be setup to automatically update the inner API client with a new token every time the expiration of the token is hit.

In both cases we start by getting a reference to the ApiClient intance:

const { ApiClient } = require('frick-sierra');

We use now this detail to initialize the API Authentication:

const { SierraAuthentication } = require('frick-sierra');
const auth = new SierraAuthentication(ApiClient.instance, '<the base URL for the Sierra API>');

With one shot authentication we need only to call the authentication method:

await auth.authenticate('username', 'password');

The inner ApiClient is now authorized and will be able to make API calls.

Since the tokens will expire - by default every 3600 seconds from issue, we can setup the authentication to renew the token and update the ApiClient when the tokens expire:

auth.startAutoAuth();

This will renew the tokens 300 seconds before they expire automatically. You can change the tolerance to another value when you create the SierraAuthentication instance. For example, to renew the tokens 30 seconds before they expire you can create the instance like this:

const auth = new SierraAuthentication(ApiClient.instance, '<the base URL for the Sierra API>', 30);

When you are done and you want to stop the automatic authentication updates:

auth.stopAutoAuth();

Generate the API Client from scratch

export GENERATOR='https://generator.swagger.io/api/gen/clients/javascript'
export DOCS='https://arcade.nyarc.org/iii/sierra-api/docs'
curl -X POST -H "content-type:application/json" -d "{\"swaggerUrl\": \"${DOCS}\"}" ${GENERATOR}

The generator will return a JSON object:

{
    "code":"xxxxxxx",
    "link":"xxxxxxx"
}

The link property is a link to a ZIP file containing the client. You can now fetch the client.

wget -q -O api-client.zip https://generator.swagger.io/api/gen/download/<id>

Unzip api-client.zip in the root of this project and it will create the javascript-client folder.

Patch the generated Sierra client:

(cd javascript-client && patch -p1 < ../utils/api-client.patch)

Run:

npm i

Current Tags

  • 1.1.4                                ...           latest (a month ago)

6 Versions

  • 1.1.4                                ...           a month ago
  • 1.1.3                                ...           a month ago
  • 1.1.2                                ...           a month ago
  • 1.1.1                                ...           a month ago
  • 1.1.0                                ...           a month ago
  • 1.0.1                                ...           a month ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 61
Dependencies (5)
Dev Dependencies (7)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |