BitBalloon Node Client
BitBalloon is a hosting service for the programmable web. It understands your documents, processes forms and lets you do deploys, manage forms submissions, inject javascript snippets into sites and do intelligent updates of HTML documents through it's API.
Installation
Install by running
npm install bitballoon
Authenticating
Register a new application at https://www.bitballoon.com/applications to get your Oauth2 secret and key.
Once you have your credentials you can instantiate a BitBalloon client.
var bitballoon = client = bitballoon;
Typically you'll have an access_token
stored that you want to instantiate the client with:
var client = bitballoon.createClient({access_token: "my-access-token"});
A client need an access token before it can make requests to the BitBalloon API. Oauth2 gives you two ways to get an access token:
- Authorize from credentials: Authenticate directly with your API credentials.
- Authorize from a URL: send a user to a URL, where she can grant your access API access on her behalf.
The first method is the simplest, and works when you don't need to authenticate on behalf of some other user:
var client = bitballoon; client;
To authorize on behalf of a user, you first need to send the user to a BitBalloon url where she'll be asked to grant your application permission. Once the user has visited that URL, she'll be redirected back to a redirect URI you specify (this must match the redirect URI on file for your Application). When the user returns to your app, you'll be able to access a code
query parameter, that you can use to obtain the final access_token
var client = bitballoon; var url = client; // Send the client to the url, they will be redirected back to the redirect_uri// Once they are back at your url, grab the code query param and use it to authorize client;
Deploy a new version of a site
If you're just going to deploy a new version of a site from a script, the module exports a simple deploy method that will handle this:
var bitballoon = ; bitballoon;
Sites
Getting a list of all sites you have access to:
client;
Getting a specific site by id:
client
Creating a new empty site:
client To deploy a site from a dir and wait for the processing of the site to finish: ```jsclient.createSite({}, function(err, site) { site.createDeploy({dir: "/tmp/my-site"}, function(err, deploy) { deploy.waitForReady(function(deploy) { console.log("Deploy is done: ", deploy); }); });});
Creating a new deploy for a site from a zip file:
client.site(id, function(err, site) { if (err) return console.log("Error finding site %o", err); site.createDeploy({zip: "/tmp/my-site.zip"}, function(err, deploy) { if (err) return console.log("Error updating site %o", err); deploy.waitForReady(function(err, deploy) { if (err) return console.log("Error updating site %o", err); console.log("Site redeployed"); }); });})
Update the name of the site (its subdomain), the custom domain and the notification email for form submissions:
site;
Deleting a site:
site;
Forms
Access all forms you have access to:
clientforms { // do work}
Access forms for a specific site:
client;
Access a specific form:
clientformid { if err return console; // do work};
Access a list of all form submissions you have access to:
client;
Access submissions from a specific site
client;
Access submissions from a specific form
clientformid { if err return console; form;};
Get a specific submission
client
Files
Access all files in a site:
client;
Get a specific file:
client;
Deploys
Access all deploys for a site
site;
Access a specific deploy
site;
Create a new deploy:
site
Create a draft deploy (wont get published after processing):
site
Publish a deploy (makes it the current live version of the site)
site;
Snippets
Snippets are small code snippets injected into all HTML pages of a site right before the closing head or body tag. To get all snippets for a site:
client;
Get a specific snippet
client;
Add a snippet to a site
You can specify a general
snippet that will be inserted into all pages, and a goal
snippet that will be injected into a page following a successful form submission. Each snippet must have a title. You can optionally set the position of both the general and the goal snippet to head
or footer
to determine if it gets injected into the head tag or at the end of the page.
client;
Update a snippet
snippet;
Delete a snippet
snippet;
Users
The user methods are mainly useful for resellers. Creating, deleting and updating users are limited to resellers.
Getting a list of users
client;
Getting a specific user
client;
Creating a new user (email
is required, uid
is optional. Both must be unique)
client;
Updating a user
client;
Deleting a user
client;
Getting sites belonging to a user
client;
DNS
Resellers can create and manage DNS Zones through the BitBalloon API.
Getting a list of DNS Zones:
client;
Getting a specific DNS zone:
client;
Creating a new zone
client;
Deleting a zone
client;
Getting records for a zone
zone;
Getting a specific record
zone;
Adding a new record (supported types: A, CNAME, TXT, MX)
zone;
Deleting a record
record;
Access Tokens
Resellers can use the node client to create and revoke access tokens on behalf of their users. To use any of these methods your OAuth access token must belong to a reseller admin user.
Creating an access token:
client;
The user must have either an email or a uid (or both) as a unique identifier. If the user doesn't exist, a new user will be created on the fly.
Deleting an access token:
client;