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 = require('divshot');
Standalone
<script src="/path/to/divshot.standalone.min.js"></div>
###Instantiate
var api = Divshot.createClient({
client_id: '123abc',
email: 'someone@divshot.com',
password: 'somepassword123!',
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;
response.access_token;
}, function (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) {
}, function (error) {
});
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.auth({store: true}, function(error, token, user){
});
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()) {
} else {
}
###Angular Module
Located at /dist/divshot.angular.js
angular.module('myApp', ['divshot'])
.config(function (divshotProvider) {
divshotProvider.configure({
token: 'divshot_api_access_token'
});
}).
controller('SomeCtrl', function ($scope, divshot) {
$scope.apps = divshot.apps.list();
});
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.module('myApp', ['divshot'])
.config(function (divshotProvider) {
divshotProvider.configure({
token: 'divshot_api_access_token'
});
}).
controller('SomeCtrl', function ($scope, divshot) {
divshot.withCredentials(true);
divshot.xhr('withCredentials', true);
});
###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.
api.user.authenticate(function (err, token) {
});
api.user.setCredentials({
email: 'someone@divshot.com',
password: 'somepassword123!',
token: 'some_really_long_access_token_from_divshot'
});
api.user.self().then(function (user) {
});
api.user.id(userId).get().then(function (user) {
});
var user = api.user.id(userId);
user.update({
name: 'First Last'
}).then(function (user) {
});
api.user.setWelcomed().then(function () {
});
api.user.deleteAcccount(user@email.com).then(function () {
});
User password
divshot.user.password.update({
password: 'Password123',
password_confirm: 'Password123'
}).then(function (res) {
});
divshot.password.reset(userId).then(function (res) {
});
User Emails
divshot.user.emails.add('something@aol.com').then(function (res) {
});
divshot.user.emails.primary('something@aol.com').then(function (res) {
});
divshot.user.emails.remove('something@aol.com').then(function (res) {
});
divshot.user.emails.resend('something@aol.com').then(function (res) {
});
Organizations
divshot.organizations.list().then(function (orgs) {
});
divshot.organizations.id(someOrgId).get().then(function (org) {
});
divshot.organizations.id(someOrgId).apps.list().then(function (apps) {
});
divshot.organizations.create({
name: 'name',
nick: 'nick',
billing_email: 'someone@aol.com',
gravatar_email: 'someone@aol.com'
}).then(function (res) {
});
divshot.organizations.id(someOrgId).update({
name: 'name',
billing_email: 'someone@aol.com',
gravatar_email: 'someone@aol.com',
etc: 'other stuff'
}).then(function (res) {
});
Organization Members
divshot.organizations.id(someOrg).members.list().then(function (members) {
});
divshot.organizations.id(someOrg).members.create({
name: email,
email: email
}).then(function (res) {
});
divshot.organizations.id(someOrg).members.id(memberid).update({
admin: false
}).then(function (res) {
});
divshot.organizations.id(someOrg).members.id(memberId).remove().then(function () {
});
Apps
api.apps.list().then(function (apps) {
});
api.apps.create('app-name').then(function (app) {
});
api.apps.createFromObject(params).then(function (app) {
});
var app = api.apps.id('app name');
app.get().then(function (app) {
});
app.remove().then(function (res) {
});
Builds
app.builds.list(function (err, builds) {
});
app.builds.id('build id').get(function (err, build) {
});
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) {
});
app.releases.env('production').rollback(function (err, response) {
});
app.releases.env('production').rollbackTo('v12').then(function () {
});
app.releases.env('production').promote('staging', function (err, callback) {
});
###Domains
app.domains.list().then(function(domains) {
});
app.domains.add('www.domain.com').then(function (response) {
});
app.domains.remove('www.domain.com').then(function (response) {
});
Subscription
Update data associated with an App's subscription
app.subscription.update('card number').then(function (res) {
});
Webhooks
Manipulate webhooks associated with your app
app.webhooks.list().then(function (response) {
});
app.webhooks.create({url: 'some-url.com', active: true}).then(function () {
});
app.webhooks.resume(hook).then(function () {
});
app.webhooks.pause(hook).then(function () {
});
app.webhooks.remove(hookId).then(function () {
});
###App Environment Configuration
app.env('development').config({
auth: 'username:password'
}, function (err, response) {
});
Build
grunt build