blue-trunk-commons

3.0.69 • Public • Published

blue-trunk-commons

This module provides classes which can facilitate access to the Blue Trunk API, and manage some of the complexities involved in using the API.

Documentation for the Blue Trunk API can be found here.

NPM JavaScript Style Guide

Installation

npm install --save blue-trunk-commons

Usage

LoginService

Setup

import { LoginService } from 'blue-trunk-commons'
...
let loginService = new LoginService(/*Hostname, or blank for default*/)

Login As User

loginService.login(
    myUser, 
    (response) => {
        response.then(returnedUser => {
            ...
        })        
    },
    (response) => {
        reponse.then(failedResponse => {
            ...
        })
    }
) 

Register

loginService.register(
    newUser, 
    (response) => {
        response.then(newlyRegisteredUser => {
            ...
        })        
    },
    (response) => {
        reponse.then(failedResponse => {
            ...
        })
    }
) 

Get Recovery Code

loginService.getRecoveryCode(
    myEmail, 
    (response) => {
        response.then(recovery => {
            ...
        })        
    },
    (response) => {
        reponse.then(failedResponse => {
            ...
        })
    }
) 

Use Recovery Code

loginService.useRecoveryCode(
    myEmail,
    newPassword,
    recoveryCode,
    (response) => {
        response.then(user => {
            ...
        })        
    },
    (response) => {
        reponse.then(failedResponse => {
            ...
        })
    }
) 

PostService

Setup

import { PostService } from 'blue-trunk-commons';
...
var postService = new PostService()

Get Posts (One Page)

The "after" is a Date object, and this call returns all posts after this date. For example, an after value of Dec. 25 would return all posts from Dec. 24, Dec. 23 etc. until there are no more posts or until the count has been reached.

postService.getPostsAfter(
    authorId,
    numberOfPostsToFetch,
    after,
    (response) => {
        response.then(user => {
            ...
        })        
    },
    (response) => {
        reponse.then(failedResponse => {
            ...
        })
    }
) 

Testing

The tests for this module require a functioning instance of the BlueTrunk API running locally. Setting up and tearing down this test instance of the API is handled automatically by test.sh.

To use this script, run either of the following commands:

sh test.sh
--OR--
node run test

Readme

Keywords

none

Package Sidebar

Install

npm i blue-trunk-commons

Weekly Downloads

88

Version

3.0.69

License

none

Unpacked Size

408 kB

Total Files

6

Last publish

Collaborators

  • ndrwksr
  • petersonlu