Divshot API
Wrapper for the Divshot API.
Contents
Install
NPM
npm install divshot-api --save
Bower
bower install divshot --save
Usage
Refer to the Narrator api for a more in depth understanding of all available methods.
CommonJS (Node/Browserify)
var Divshot = ;
Standalone
<script src="/path/to/divshot.standalone.min.js"></div>
Instantiate
var api = Divshot;
Browser Authentication
The Divshot API wrapper provides a simple, popup-based authentication mechanism for
easily authenticating a user without requiring the handling of usernames or passwords.
To use browser authentication, simply instantiate a client and call the auth
method:
divshot.auth(type, options, callback)
This method returns a promise but takes an optional callback. type
should be either
password
or github
(defaults to password
).
var api = Divshot; divshot;
Password Authentication
If you need to accept an email and password directly, you can do so as in the following example. Passwords MUST NOT be stored and should only come from direct user input (e.g. a form field).
divshot;
Cookie Token Storage
For convenience, the auth
method allows you to store a cookie with an encoded access token
to keep the user logged into Divshot. Simply pass the store: true
option to auth
:
api;
This will automatically create a cookie on the current domain to store the access token for one
week. On subsequent page loads you can use the authWithCookie()
method to authenticate a client
based on the cookie. This method will return true
if a cookie was found and false
otherwise.
if api // cookie found, api is now authenticated and can // make calls to retrieve protected resources else // no cookie found, display an auth button etc
Angular Module
Located at /dist/divshot.angular.js
angular ;
Custom XHR arguments
Custom XHR arguments can be set to be sent with each request. Refer to Angular's $http documentation for which arguments are supported.
angular ;
User
By default, the authenticate
method will be called on each request as a pre hook. If a token is provided, this does not create another http request.
apiuser; apiuser; // User dataapiuserself;// ORapiuseriduserId; // Update uservar user = apiuseriduserId;user; // Set welcomed for new usersapiuser; // Delete accountapiuser;
User password
// Change passworddivshotuserpassword; // Reset password if forgottendivshotpassword;
User Emails
// Add emaildivshotuseremails; // Set primary emaildivshotuseremails; // Remove emaildivshotuseremails; // Resend emaildivshotuseremails;
Organizations
// Users orgsdivshotorganizations; // A single organizationdivshotorganizationsidsomeOrgId; // Apps from an organizationdivshotorganizationsidsomeOrgIdapps; // Create organizationdivshotorganizations; // Update organizationdivshotorganizationsidsomeOrgId;
Organization Members
// Get org membersdivshotorganizationsidsomeOrgmembers; // Invite members to organizationdivshotorganizationsidsomeOrgmembers; // Update a member in organiztiondivshotorganizationsidsomeOrgmembersidmemberid; // Remove a member from an organizationdivshotorganizationsidsomeOrgmembersidmemberId;
Apps
// List appsapiapps; // Create an appapiapps; // Create an app from objectapiapps; // A specific appvar app = apiappsid'app name';app; // Delete an appapp;
Builds
appbuilds; appbuildsid'build id'; appbuildsid'build id'; appbuildsid'build id';
Releases
appreleases; appreleases; appreleases; // Rollback to specific versionappreleases; appreleases;
Domains
// List domains for an appappdomains; // Add a domainappdomains; // Remove a domainappdomains;
Subscription
Update data associated with an App's subscription
appsubscription;
Webhooks
Manipulate webhooks associated with your app
appwebhooks; appwebhooks; appwebhooks; appwebhooks; appwebhooks;
App Environment Configuration
app;
Build
grunt build