var api = Divshot.createClient({ client_id: '123abc', // MUST be specified email: 'someone@divshot.com', password: 'somepassword123!', // OR token: 'your divshot access token'});
###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.createClient({client_id: 'abc123'});divshot.auth().then(function(response) { response.user; // user details response.access_token; //access token}, function (error) { // do something with an error});
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.auth('password', {email: 'abby@example.com', password: 'test123'}).then(function(response) { // works just as above}, function (error) { // ditto});
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:
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.authWithCookie()) { // cookie found, api is now authenticated and can // make calls to retrieve protected resources} else { // no cookie found, display an auth button etc}
// Users orgsdivshot.organizations.list().then(function (orgs) {});// A single organizationdivshot.organizations.id(someOrgId).get().then(function (org) {});// Apps from an organizationdivshot.organizations.id(someOrgId).apps.list().then(function (apps) {});// Create organizationdivshot.organizations.create({ name: 'name', nick: 'nick', billing_email: 'someone@aol.com', gravatar_email: 'someone@aol.com'
Organization Members
// Get org membersdivshot.organizations.id(someOrg).members.list().then(function (members) {});// Invite members to organizationdivshot.organizations.id(someOrg).members.create({ name: email, email: email}).then(function (res) {});// Update a member in organiztiondivshot.organizations.id(someOrg).members.id(memberid).update({ admin: false // or true}).then(function (res) {});// Remove a member from an organizationdivshot.organizations.
Apps
// List appsapi.apps.list().then(function (apps) {});// Create an appapi.apps.create('app-name').then(function (app) {});// Create an app from objectapi.apps.createFromObject(params).then(function (app) {});// A specific appvar app = api.apps.id('app name');app.get().then(function (app) {});
Builds
app.builds.list(function (err, builds) {});app.builds.id('build id').get(function (err, build) { // Specific build by id});app.builds.id('build id').finalize(function (err, response) {});app.builds.id('build id').release('production', function (err, response) {});
###Releases
app.releases.list(function (err, releases) {});app.releases.env('production').get(function (err, release) { // Release by environment});app.releases.env('production').rollback(function (err, response) {});// Rollback to specific versionapp.releases.env('production').rollbackTo('v12').then(function () {});app.releases.env('production').promote('staging'
###Domains
// List domains for an appapp.domains.list().then(function(domains) {});// Add a domainapp.domains.add('www.domain.com').then(function (response) {});// Remove a domainapp.domains.remove('www.domain.com').then(function (response) {});