Humanity JavaScript SDK
This package provides easy access to the Humanity API and IFrame SDK.
Before using, you will need to create your application and get the Application ID at the Humanity Developers Portal.
Refer to the Humanity API Docs for the available resources.
Installation
For NodeJS
npm install humanity-js-sdk
For browsers
bower install humanity-js-sdk
Usage
NodeJS
var Humanity = ; // Instantiate auth classvar auth = 'your_client_id' 'your_redirect_uri' null 'company.view' 'your_secret'; // Generate SignIn URIvar signInUri = auth; // https://accounts.humanity.com/oauth2/authorize?client_id=your_client_id&redirect_uri=your_redirect_uri%2F&company_id=&scope=company.view&response_type=code // Redirect to the signInUri, and then depending on the http framework, set up a route for your redirect_uri// The following example is for the express frameworkapp;
Browser
Using the API
// Import the library using your desired module loader (AMD/CommonJS/ES6)// Using CommonJS as an examplevar Humanity = ; // Instantiate auth classvar auth = 'your_client_id' 'your_redirect_uri' null 'company.view'; // Obtain auth data from hash if it's setvar authData = Humanity; if authDataaccess_token Humanity; else // Redirect to the OAuth2 service windowlocationhref = auth;
Using the Application framework
We developed a way for your app to communicate with the Humanity app in an unique way, allowing it to modify parts of the Humanity app and utilize core modules functionality.
// Using CommonJS as an examplevar Humanity = ; /** Get Company Id** Obtain company_id so the application doesn't need to ask the user for the company*/HumanityIFrame; /** Populating the 3 dots Menu** This menu is used for navigating the application pages*/ // First set a listener for the event, so we are able to act when menu item is clickedHumanityIFrame; HumanityIFrame; /** Close subpage** Closes the subpage. Note this only works when called from the subpage.*/ HumanityIFrame; /** Post to main** Use this to post messages to the main frame. Useful when you want to notify* the main application about some changes from the subpage.*/ // First set a listener for the event on the main frame.HumanityIFrame; // Then call it from the subpageHumanityIFrame; /** Open Subpage** Open a subpage from your app in the native Humanity subpage*/ // Path is relative to the application rootHumanityIFrame; /** Notification** Displays native Humanity notification*/ HumanityIFrame; /** Set Controls** Set the Humanity header controls*/ HumanityIFrame; /** Set Subpage Controls** Set the subpage header and footer*/ HumanityIFrame;
Building
npm install
bower install
grunt build