brickset

0.3.1 • Public • Published

node-brickset NPM version Build Status

NodeJS adapter to Brickset API

What This Module Provides

Brickset is an online LEGO® set guide.

The Brickset API v2 provides an API into the site's functionality. This module eases authentication and provides Promise wrappers around these API functions.

The API is a SOAP API, and this module leverages node-soap to access it. Promises are provided by Q.

Like node-soap, as the WSDL file changes, so does the JS API--client object methods are generated automatically.

You need an API key from Brickset to use this module; get one here. Many functions also require a Brickset user name and password. It's recommended to store these in the environment variables BRICKSET_API_KEY, BRICKSET_USERNAME, and BRICKSET_PASSWORD, respectively.

Passwords are sent in plaintext; Brickset does not provide https. Use a unique password!

This module supports the Brickset API v2 only.

Installation

npm install brickset

Usage

 
var brickset = require('brickset');
 
brickset({
  api_key: YOUR_API_KEY,
  username: YOUR_BRICKSET_USERNAME, // optional, for functions requiring auth
  password: YOUR_BRICKSET_PASSWORD  // ditto
})
  .then(function(bs) {
    // this function requires auth; login happens automatically
    return bs.getSet({
      setID: '7722-1'
    });
  })
  .get(0) // getSet() returns an array; get first item
  .get('bricksetURL')
  .then(function(url) {
    console.log(url);
  });
 
// alternatively, you can use node-style callbacks
brickset({
  api_key: YOUR_API_KEY,
  username: YOUR_BRICKSET_USERNAME, // optional, for functions requiring auth
  password: YOUR_BRICKSET_PASSWORD  // ditto
}, function(err, bs) {
  bs.getSet({
    setID: '7722-1'
  }, function(err, legoSet) {
    // etc.
  });
});

Cache Busting

For performance, the module will cache the API definition (WSDL) file. If you do not want to cache this information, use:

brickset({
  api_key: YOUR_API_KEY,
  cache: false
});

The definition is located in /path/to/brickset/lib/.BricksetAPIv2Soap.wsdl (thus, if you have installed globally for some reason, you may incur permissions issues if superuser access is needed to write to this file).

Since the API is in beta as of this writing, it's subject to change. You should probably remove the cache every so often until it is finalized.

Brickset API URL

If the URL of the WSDL should change, you can define a custom URL:

brickset({
  api_key: YOUR_API_KEY,
  url: 'http://some/url.wsdl'
});

Testing

  1. (Fork and) clone this repo
  2. npm install
  3. npm test

Resources

License

MIT

Author

Christopher Hiller

Package Sidebar

Install

npm i brickset

Weekly Downloads

1

Version

0.3.1

License

MIT

Last publish

Collaborators

  • boneskull