Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote-tracking branch 'lholmquist/inlineexamples'

  • Loading branch information...
commit fcd3fbf22d28ad072dba4072639caf9dafe483ea 2 parents 85deb6b + 1405c2d
@kborchers kborchers authored
View
76 src/authentication/adapters/rest.js
@@ -23,6 +23,25 @@
@param {Object} [settings.endpoints={}] - a set of REST endpoints that correspond to the different public methods including enroll, login and logout
@param {String} [settings.tokenName="Auth-Token"] - defines the name used for the token header when using agAuth
@returns {Object} The created auth module
+ @example
+ //Create an empty Authenticator
+ var auth = AeroGear.Auth();
+
+ //Add a custom REST module to it
+ auth.add( "module1", {
+ agAuth: true,
+ baseURL: "http://customURL.com"
+ });
+
+ //Add a custom REST module to it with custom security endpoints
+ auth.add( "module2", {
+ agAuth: true,
+ endpoints: {
+ enroll: "register",
+ login: "go",
+ logout: "leave"
+ }
+ });
*/
AeroGear.Auth.adapters.Rest = function( moduleName, settings ) {
// Allow instantiation without using new
@@ -181,6 +200,25 @@ AeroGear.Auth.adapters.Rest = function( moduleName, settings ) {
// Enroll a new user
auth.enroll( data );
+
+ //Add a custom REST module to it with custom security endpoints
+ var custom = AeroGear.Auth({
+ name: "customModule",
+ settings: {
+ agAuth: true,
+ endpoints: {
+ enroll: "register",
+ login: "go",
+ logout: "leave"
+ }
+ }).modules[ 0 ],
+ data = { userName: "user", password: "abc123", name: "John" };
+
+ custom.enroll( data, {
+ baseURL: "http://customurl/",
+ success: function( data ) { ... },
+ error: function( error ) { ... }
+ });
*/
AeroGear.Auth.adapters.Rest.prototype.enroll = function( data, options ) {
options = options || {};
@@ -248,6 +286,25 @@ AeroGear.Auth.adapters.Rest.prototype.enroll = function( data, options ) {
// Enroll a new user
auth.login( data );
+
+ //Add a custom REST module to it with custom security endpoints
+ var custom = AeroGear.Auth({
+ name: "customModule",
+ settings: {
+ agAuth: true,
+ endpoints: {
+ enroll: "register",
+ login: "go",
+ logout: "leave"
+ }
+ }).modules[ 0 ],
+ data = { userName: "user", password: "abc123", name: "John" };
+
+ custom.login( data, {
+ baseURL: "http://customurl/",
+ success: function( data ) { ... },
+ error: function( error ) { ... }
+ });
*/
AeroGear.Auth.adapters.Rest.prototype.login = function( data, options ) {
options = options || {};
@@ -311,6 +368,25 @@ AeroGear.Auth.adapters.Rest.prototype.login = function( data, options ) {
// Enroll a new user
auth.logout();
+
+ //Add a custom REST module to it with custom security endpoints
+ var custom = AeroGear.Auth({
+ name: "customModule",
+ settings: {
+ agAuth: true,
+ endpoints: {
+ enroll: "register",
+ login: "go",
+ logout: "leave"
+ }
+ }).modules[ 0 ],
+ data = { userName: "user", password: "abc123", name: "John" };
+
+ custom.logout({
+ baseURL: "http://customurl/",
+ success: function( data ) { ... },
+ error: function( error ) { ... }
+ });
*/
AeroGear.Auth.adapters.Rest.prototype.logout = function( options ) {
options = options || {};
View
10 src/data-manager/adapters/memory.js
@@ -20,6 +20,13 @@
@param {Object} [settings={}] - the settings to be passed to the adapter
@param {String} [settings.recordId="id"] - the name of the field used to uniquely identify a "record" in the data
@returns {Object} The created store
+ @exmaple
+
+ //Create an empty DataManager
+ var dm = AeroGear.DataManager();
+
+ //Add a custom memory store
+ dm.add( "newStore", { recordId: "customID" });
*/
AeroGear.DataManager.adapters.Memory = function( storeName, settings ) {
// Allow instantiation without using new
@@ -139,6 +146,9 @@ AeroGear.DataManager.adapters.Memory = function( storeName, settings ) {
// Get an array of all data in the store
var allData = dm.read();
+
+ //Read a specific piece of data based on an id
+ var justOne = dm.read( 12345 );
*/
AeroGear.DataManager.adapters.Memory.prototype.read = function( id ) {
var filter = {};
View
49 src/data-manager/adapters/session-local.js
@@ -22,6 +22,13 @@
@param {String} [settings.recordId="id"] - the name of the field used to uniquely identify a "record" in the data
@param {String} [settings.storageType="sessionStorage"] - the type of store can either be sessionStorage or localStorage
@returns {Object} The created store
+ @exmaple
+
+ //Create an empty DataManager
+ var dm = AeroGear.DataManager();
+
+ //Add a custom SessionLocal store using local storage as its storage type
+ dm.add( "newStore", { recordId: "customID", storageType: "localStorage" });
*/
AeroGear.DataManager.adapters.SessionLocal = function( storeName, settings ) {
// Allow instantiation without using new
@@ -80,6 +87,20 @@ AeroGear.DataManager.adapters.SessionLocal.prototype = Object.create( new AeroGe
@param {AeroGear~errorCallbackStorage} [options.success] - A callback to be called if the save was successful. This probably isn't necessary since the save is synchronous but is provided for API symmetry.
@param {AeroGear~successCallbackStorage} [options.reset] - If true, this will empty the current data and set it to the data being saved
@returns {Array} Returns the updated data from the store or in the case of a storage error, returns the unchanged data
+ @example
+ var dm = AeroGear.DataManager([{ name: "tasks", type: "SessionLocal" }]).stores[ 0 ];
+
+ // Store a new task
+ dm.save({
+ title: "Created Task",
+ date: "2012-07-13",
+ ...
+ });
+
+ // Update an existing piece of data
+ var toUpdate = dm.read()[ 0 ];
+ toUpdate.data.title = "Updated Task";
+ dm.save( toUpdate );
*/
save: {
value: function( data, options ) {
@@ -113,6 +134,34 @@ AeroGear.DataManager.adapters.SessionLocal.prototype = Object.create( new AeroGe
@memberof AeroGear.DataManager.adapters.SessionLocal
@param {String|Object|Array} toRemove - A variety of objects can be passed to remove to specify the item or if nothing is provided, all data is removed
@returns {Array} Returns the updated data from the store
+ @example
+ var dm = AeroGear.DataManager([{ name: "tasks", type: "SessionLocal" }]).stores[ 0 ];
+
+ // Store a new task
+ dm.save({
+ title: "Created Task"
+ });
+
+ // Store another new task
+ dm.save({
+ title: "Another Created Task"
+ });
+
+ // Store one more new task
+ dm.save({
+ title: "And Another Created Task"
+ });
+
+ // Remove a particular item from the store by its id
+ var toRemove = dm.read()[ 0 ];
+ dm.remove( toRemove.id );
+
+ // Remove an item from the store using the data object
+ toRemove = dm.read()[ 0 ];
+ dm.remove( toRemove );
+
+ // Delete all remaining data from the store
+ dm.remove();
*/
remove: {
value: function( toRemove ) {
View
7 src/data-manager/aerogear.datamanager.js
@@ -32,6 +32,13 @@
// Create multiple stores using the default adapter
var dm3 = AeroGear.DataManager( [ "tasks", "projects" ] );
+
+ //Create a custom store
+ var dm3 = AeroGear.DataManager([{
+ name: "mySessionStorage",
+ type: "SessionLocal",
+ id: "customID"
+ }])
*/
AeroGear.DataManager = function( config ) {
// Allow instantiation without using new
View
115 src/pipeline/adapters/rest.js
@@ -30,6 +30,26 @@
@param {String} [settings.recordId="id"] - the name of the field used to uniquely identify a "record" in the data
@param {Number} [settings.timeout=60] - the amount of time, in seconds, to wait before timing out a connection and firing the complete callback for that request
@returns {Object} The created pipe
+ @exmaple
+ //Create an empty pipeline
+ var pipeline = AeroGear.Pipeline();
+
+ //Add a new Pipe with a custom baseURL, custom endpoint and default paging turned on
+ pipeline.add( "customPipe", {
+ baseURL: "http://customURL.com",
+ endpoint: "customendpoint",
+ pageConfig: true
+ });
+
+ //Add a new Pipe with a custom paging options
+ pipeline.add( "customPipe", {
+ pageConfig: {
+ metadataLocation: "header",
+ previousIdentifier: "back",
+ nextIdentifier: "forward"
+ }
+ });
+
*/
AeroGear.Pipeline.adapters.Rest = function( pipeName, settings ) {
// Allow instantiation without using new
@@ -248,6 +268,79 @@ AeroGear.Pipeline.adapters.Rest = function( pipeName, settings ) {
...
}
});
+
+ //JSONP - Default JSONP call to a JSONP server
+ myPipe.read({
+ jsonp: true,
+ success: function( data ){
+ .....
+ }
+ });
+
+ //JSONP - JSONP call with a changed callback parameter
+ myPipe.read({
+ jsonp: {
+ callback: "jsonp"
+ },
+ success: function( data ){
+ .....
+ }
+ });
+
+ //Paging - using the default weblinking protocal
+ var defaultPagingPipe = AeroGear.Pipeline([{
+ name: "webLinking",
+ settings: {
+ endpoint: "pageTestWebLink",
+ pageConfig: true
+ }
+ }]).pipes[0];
+
+ //Get a limit of 2 pieces of data from the server, starting from the first page
+ //Calling the "next" function will get the next 2 pieces of data, if available.
+ //Similarily, calling the "previous" function will get the previous 2 pieces of data, if available
+ defaultPagingPipe.read({
+ offsetValue: 1,
+ limitValue: 2,
+ success: function( data, textStatus, jqXHR ) {
+ data.next({
+ success: function( data ) {
+ data.previous({
+ success: function() {
+ }
+ });
+ }
+ });
+ }
+ });
+
+ //Create a new Pipe with a custom paging options
+ var customPagingPipe = AeroGear.Pipeline([{
+ name: "customPipe",
+ settings: {
+ pageConfig: {
+ metadataLocation: "header",
+ previousIdentifier: "back",
+ nextIdentifier: "forward"
+ }
+ }
+ }]).pipes[0];
+
+ //Even with custom options, you use "next" and "previous" the same way
+ customPagingPipe.read({
+ offsetValue: 1,
+ limitValue: 2,
+ success: function( data, textStatus, jqXHR ) {
+ data.next({
+ success: function( data ) {
+ data.previous({
+ success: function() {
+ }
+ });
+ }
+ });
+ }
+ });
*/
AeroGear.Pipeline.adapters.Rest.prototype.read = function( options ) {
var url, success, error, extraOptions,
@@ -372,8 +465,10 @@ AeroGear.Pipeline.adapters.Rest.prototype.read = function( options ) {
});
// Update an existing piece of data
- var toUpdate = myPipe.data[ 0 ];
- toUpdate.data.title = "Updated Task";
+ var toUpdate = {
+ id: "Some Existing ID",
+ title: "Updated Task"
+ }
myPipe.save( toUpdate );
*/
AeroGear.Pipeline.adapters.Rest.prototype.save = function( data, options ) {
@@ -441,26 +536,24 @@ AeroGear.Pipeline.adapters.Rest.prototype.save = function( data, options ) {
// Store a new task
myPipe.save({
- title: "Created Task"
+ title: "Created Task",
+ id: 1
});
// Store another new task
myPipe.save({
- title: "Another Created Task"
+ title: "Another Created Task",
+ id: 2
});
// Store one more new task
myPipe.save({
- title: "And Another Created Task"
+ title: "And Another Created Task",
+ id: 3
});
// Remove a particular item from the server by its id
- var toRemove = myPipe.data[ 0 ];
- myPipe.remove( toRemove.id );
-
- // Remove an item from the server using the data object
- toRemove = myPipe.data[ 0 ];
- myPipe.remove( toRemove );
+ myPipe.remove( 1 );
// Delete all remaining data from the server associated with this pipe
myPipe.remove();
View
7 src/pipeline/aerogear.pipeline.js
@@ -32,6 +32,13 @@
// Create multiple pipes using the default adapter
var pl3 = AeroGear.Pipeline( [ "tasks", "projects" ] );
+
+ //Create a new REST pipe with a custom ID
+ var pl4 = AeroGear.Pipeline([{
+ name: "customPipe",
+ type: "rest",
+ recordId: "CustomID"
+ }])
*/
AeroGear.Pipeline = function( config ) {
// Allow instantiation without using new
Please sign in to comment.
Something went wrong with that request. Please try again.