rocker.js
This is a javascript client used to communicate with a Rocker server. This script works both in a browser and as a nodejs module. (The Rocker server is a restful backend service (LAMP), here you can read more about PHP-Rocker)
Example
var Rocker = server = 'https://api.website.com/'; var userMeta = birth : '1980-12-04' gender : 'male' country: 'Finland';server;
Methods
- setSecret( s ) — In case using encrypted authentication (more info below)
- setUser( email, password ) — Set authentication credentials
- me( callback ) — Get user data belonging to authenticated user
- createUser( email, nick, pass, meta, callback ) — Create a new user
- saveFile( content, name, contentType, callback, base64Decode, imageVersions) — Save a file related to authenticated user (more info below)
- fileUpload( inputElement, callback, beforeUploadCallback, imageVersions ) — Browser only (more info below)
- removeFile( name, callback )
- request( obj ) — Request an API operation. Example
var server = 'https://api.website.com/';server;server;
Here you can read more about which operations that is available out-of-the-box
RC4 encrypted authentication
If you're using RC4 encrypted authentication you will have to give the shared secret to your client before making any requests that requires authentication. Example:
var server = 'https://api.website.com/';server;server;server;
Storing files
Browser example (requires support for FileReader):
Nodejs example:
var fs = mime = Rocker = server = 'https://api.website.com/'; // Give client user credentialsserver; // Load image into base64 encoded string (only binary files needs to be base64 encoded)var imgBase64 = fs 'binary' mimeType = mime; // Declare callbackvar { if status == 201 // All is fine :) console; else console; console; }; // Send file to serverserver;