Skip to content

jacobmcdorman/nationbuilder-node-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NationBuilder Node SDK

This is a quick reference for usage and design. This should "just get the point across"...

Usage

The SDK is required as a constructor function. The constructor has two parameters: slug and authenticator. The slug is the NationBuilder subdomain associated with the account for which the SDK connects. The authenticator is the object used by resource requests to pre-authenticate a request - currently BasicAuth is the only supported authentication scheme.

// require
const NationBuilder = require('nationbuilder-node');

// setup
const auth = NationBuilder.BasicAuth('my-test-token');
const nb = new NationBuilder('my-slug', auth);

After the NationBuilder SDK is instantiated, the resources methods can be accessed via the pattern nb.[resource].[resource-method].

nb.people.list({limit: 5})
    .then(list => {
        // first page of people: 5 per
        console.log("people:", list.people);
        return list.next();
    })
    .then(list => {
        // second page of people...
    });

For more examples checkout test/resources-people-test.js

Design

  • src/index.js: the SDK facade; all the resources are linked here.
  • src/resource.js: the common functionality for request, i.e. authenticating making a request
  • src/resources/*.js: all the resource API definitions are defined here; this is where new resources are added, i.e. all the NationBuilder resources models
  • src/authenticators/*.js: the authenticators. Only BasicAuth is defined... OAuth authenticators would be added here and should implement the same interface as BasicAuth

About

NationBuilder node demo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published