Node.js API for Rhizome.
- Logging in now updates all authenticating app information (not just the tokens)
npm install rhizome-js-api
First of all you need to initialise Rhizome with a valid App Token. App Tokens are created in Rhizome by the system administrator.
const Rhizome = require('rhizome-api-js');
Rhizome.init({
rhizomeUrl: 'http://rhizome.url' [DEFAULT: http://rhizome.codersforcorbyn.com],
appToken: 'Get this from the Rhizome Admin' [REQUIRED]
});
Once you have initialised Rhizome you can use it as follows:
This creates a Rhizome user based on OAuth2 user flow authentication leading to a token and tokenSecret. In addition to the basic information Rhizome stores these properties:
var user = {
app: 'twitter',
id: profile.id,
token: token,
tokenSecret: tokenSecret,
name: profile._json.name,
username: profile.username,
profileUrl: `https://twitter.com/${profile.username}`,
profileImgUrl: profile._json.profile_image_url,
bannerImgUrl: profile._json.profile_banner_url
};
Rhizome.Auth.findOrCreateUser(user)
.then(rhizomeUser => cb(null, rhizomeUser))
.catch(Logging.Promise.logError());
User data is shared across all Rhizome applications based on trusted OAuth application Ids.
User metadata is silo'ed on a per application basis. Specify the default value for when there is no metadata in the database.
Rhizome.User.loadMetadata(userRhizomeId, 'KEY_NAME', [])
.then(data => Logging.log(data))
.catch(err => Logging.log(err));
Rhizome.User.saveMetadata(userRhizomeId, 'KEY_NAME', {foo:true, bar:false})
.then(data => Logging.log(data))
.catch(err => Logging.log(err));
Rhizome.User.load(rhizomeUserId)
.then(u => {
var twauth = u.auth.find(a => a.app === 'twitter');
if (!twauth) {
return;
}
// Do something useful with the user twauth.token && twauth.tokenSecret
Applications have metadata (specify the default value for when there is no metadata in the database):
Rhizome.App.loadMetadata('KEY_NAME', [])
.then(data => Logging.log(data))
.catch(err => Logging.log(err));
Rhizome.User.saveMetadata('KEY_NAME', {foo:true, bar:false})
.then(data => Logging.log(data))
.catch(err => Logging.log(err));