Class: App

App

Represents an application

new App(apiKey, options){App}

app.js, line 27
Use this constructor to get an instance of App
Name Type Description
apiKey String Accepts Application's API key which Built.io Backend uses to identify each application.
options object Accepts Application's Options which Built.io Backend uses (Optional).
Example
// 'blt5d4sample2633b' is a dummy Application API key
// app instance using only apikey
var app = Built.App('blt5d4sample2633b');

// Setting options on app instance
// currently it only accepts 6 options i.e host, protocol, port, rtHost, rtPort and rtProtocol
var app = Built.App('blt5d4sample2633b',{
   host: 'api.built.io',
   port: 443,
   protocol: 'https'
});

Members

staticApp.Analytics

Represents analytics on Built.io Backend
Example
// 'blt5d4sample2633b' is a dummy Application API key
// Returns an instance of Analytics
var analytics = Built.App('blt5d4sample2633b').Analytics(); 

staticApp.Class

Represents a Class.

staticApp.Extension

Represents a Extension

staticApp.Installation

Represents a Installation

staticApp.Role

Represents a Role

staticApp.Upload

Represents a Upload

staticApp.User

Represents a User.

staticApp.UserRoleMapper

Represents a UserRoleMapper

Methods

disableRealtime(){App}

realtime.js, line 1036

[Only avaliable with realtime plugin]

Disables realtime connection. All requests to the server would be made using HTTP.
Example
// 'blt5d4sample2633b' is a dummy Application API key
// Returns an app in which realtime is enabled
var app = Built
          .App('blt5d4sample2633b')
          .enableRealtime();

// Disables realtime
app = app
      .disalbeRealtime();

disableUserMetrics(){App}

app.js, line 1175
Use this method to disable SDK from tracking user metrics
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').disableUserMetrics();

enableRealtime(){App}

realtime.js, line 605

[Only avaliable with realtime plugin]

Enables realtime connection. All requests to the server would be made through a socket.
Example
var app = Built
           .App('blt5d4sample2633b')
           .enableRealtime();
	

enableUserMetrics(){App}

app.js, line 1158
Tracking of user metrics is disabled by default. This method will enable the SDK to track user's information
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').enableUserMetrics();

fetch(){Promise.<App>}

app.js, line 1200
Fetches the application info
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b');
app.fetch()
.then(function(app){
   console.log(app);
});

fetchApplicationClassesSchema(){object}

app.js, line 1270
Gets' the schema of all classes on Built.io Backend
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b')
app.fetchApplicationClassesSchema()
.then(function(res){
   console.log(res);
});

getAccessToken(){String}

app.js, line 631
Returns access_token used by the app instance for authentication
Example
// 'blt5d4sample2633b' is a dummy Application API key
var accesstoken = Built.App('blt5d4sample2633b').getAccessToken() // Returns access_token

getApiKey(){String}

app.js, line 1251
Gets the application's api key
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b')
app.fetch()
.then(function(app){
   app.getApiKey();
});

getAppVariables(){object}

app.js, line 1315
Gets the application variables
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b')
app.fetch()
.then(function(app){
   app.getAppVariables();
});

getCachePolicy(){String}

app.js, line 736
Returns the cache policy being followed by the app instance
Example
// 'blt5d4sample2633b' is a dummy Application API key
Built.App('blt5d4sample2633b').getCachePolicy() === Built.CachePolicy.ONLY_NETWORK.

getDeviceID(){String}

app.js, line 1483
Returns device id used by the app instance
Example
// 'blt5d4sample2633b' is a dummy Application API key
var deviceID = Built.App('blt5d4sample2633b').getDeviceID() // Returns device_id

getExtensionKey(){String}

app.js, line 946
Gets the extension key for an application
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').setExtensionKey('bltdb28fsaMplEf1b8');
console.log(app.getExtensionKey());

getHeaders(){object}

app.js, line 1060
Returns the headers set on this instance.
Example
// 'blt5d4sample2633b' is a dummy Application API key
var headers = Built.App('blt5d4sample2633b').getHeaders();
console.log(headers)

getLastActivities(){object}

app.js, line 1291
Gets the details about the last activities performed on this application
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b')
app.getLastActivities()
.then(function(res){
   console.log(res);
});

getMasterKey(){String}

app.js, line 1004
Gets the master key for an application
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').setMasterKey('bltdb28fsaMplEf1b8');
console.log(app.getMasterKey());

getName(){String}

app.js, line 1232
Gets the application name
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b')
app.fetch()
.then(function(app){
   app.getName();
});

getRefreshToken(){String}

app.js, line 1511
Returns refresh_token used by the app instance
Example
// 'blt5d4sample2633b' is a dummy Application API key
var refreshtoken = Built.App('blt5d4sample2633b').getRefreshToken() // Returns refresh_token

getURL(){String}

app.js, line 1076
Returns the URL this application instance would use to make a HTTP request to Built.io Backend
Example
// 'blt5d4sample2633b' is a dummy Application API key
var url = Built.App('blt5d4sample2633b').getURL();
console.log(url);

getVersion(){String}

app.js, line 1094
Returns the version of Built.io Backend
Example
// 'blt5d4sample2633b' is a dummy Application API key
var version = Built.App('blt5d4sample2633b').getVersion();
console.log(version);

isRealtimeEnabled(){Boolean}

realtime.js, line 1078

[Only avaliable with realtime plugin]

Checks whether realtime is enabled on this app instance
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built
          .App('blt5d4sample2633b')
          .enableRealtime(); // Returns an app in which realtime is enabled
var bool = app
           .isRealtimeEnabled();

onRealtimeError()

realtime.js, line 1100

[Only avaliable with realtime plugin]

The callback function provided to this method would be invoked whenever an error occurs in realtime.
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built
          .App('blt5d4sample2633b')
          .enableRealtime()
          .onRealtimeError(function(error){
             // e.g invalid application_key.
          });

persistSessionWith(persistSession){App}

app.js, line 667
Sets the storage medium that should be used to maintain logged-in user's session. By default SDK tries to store session in Cookie.
Name Type Description
persistSession Constant Accepts one of the persistance option
Example
// 'blt5d4sample2633b' is a dummy Application API key
// Returns an app that would use localstorage to persist sessions
var app = Built.App('blt5d4sample2633b').persistSessionWith(Built.Session.LOCAL_STORAGE); 

removeAccessToken(){App}

app.js, line 645
Removes authentication token from the app header
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').removeAccessToken() // Removes access_token from app headers

removeDeviceID(){App}

app.js, line 1498
Removes device id from the app header
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').removeDeviceID() // Removes device id from app headers

removeExtensionKey(){App}

app.js, line 962
Removes the extension key from application
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').removeExtensionKey(); 

removeHeader(header){App}

app.js, line 772
Removes a HTTP request header
Name Type Description
header String The header key that needs to be removed
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').removeHeader('My-Custom-Header'); 

removeMasterKey(){App}

app.js, line 1019
Removes the master key from application
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').removeMasterKey(); 

removeTenant(){App}

app.js, line 1046
Removes the tenant from application
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').removeTenant();

setAccessToken(access_token){App}

app.js, line 596
Sets an authentication token in the app header
Name Type Description
access_token String Logged-in user's access_token
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').setAccessToken('abc123');

setApiKey(applicationApiKey){App}

app.js, line 991
Sets the application api key
Name Type Description
applicationApiKey String The application api key
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App().setApiKey('bltdb28fsaMplEf1b8');

setCachePolicy(cache_policy){App}

app.js, line 710
Sets the cache policy to be used. By default no data is cached.
Name Type Description
cache_policy Constant Cache Policy to be used by the application. Default to Built.CachePolicy.ONLY_NETWORK
Example
// 'blt5d4sample2633b' is a dummy Application API key
// Returns an app which would use CACHE_ELSE_NETWORK as its cache policy
var app = Built
          .App('blt5d4sample2633b')
          .setCachePolicy(Built.CachePolicy.CACHE_ELSE_NETWORK); 

setDeviceID(deviceID){App}

app.js, line 1469
Sets an device id in the app header
Name Type Description
deviceID String Device id of the user device
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').setDeviceID('abc123');

setExtensionKey(extensionKey){App}

app.js, line 932
Sets the extension key for an application
Name Type Description
extensionKey String The Extension key
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').setExtensionKey('bltdb28fsaMplEf1b8');

setHeader(header, value){App}

app.js, line 752
Sets a HTTP request header
Name Type Description
header String The header key
value String The header value
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').setHeader('My-Custom-Header','MyValue');

setHost(host){App}

app.js, line 796
Changes the host config
Name Type Description
host String The host name
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').setHost('api.built.io'); 

setMasterKey(masterKey){App}

app.js, line 977
Sets the master key for an application
Name Type Description
masterKey String The master key
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').setMasterKey('bltdb28fsaMplEf1b8');

setPort(port){App}

app.js, line 848
Changes the port config
Name Type Description
port Number The port number
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').setPort(443); 

setProtocol(protocol){App}

app.js, line 890
Sets the protocol to be used.
Name Type Description
protocol String The protocol to be used (Protocol should be either http or https)
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').setProtocol('https') 

setRtHost(host){App}

app.js, line 831
Use this method to set the host that should be used for realtime connection
Name Type Description
host String The host name
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built
          .App('blt5d4sample2633b')
          .setRtHost('realtime.built.io')
          .enableRealtime() 

setRtPort(port){App}

app.js, line 871
Changes the port number to be used for realtime connection
Name Type Description
port Number The port number
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').setRtPort(443);

setRtProtocol(port){App}

app.js, line 913
Use this method to change the protocol that should be used for realtime connection
Name Type Description
port String The port number
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').setRtProtocol('https'); 

setTenant(tenantUid){App}

app.js, line 1033
Sets the current tenant for this application
Name Type Description
tenantUid String The tenant uid value
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').setTenant('samepl_tenant');

setTrackAnonymously(){object}

app.js, line 1381
By default, the logged-in user's uid is sent to the server for analysis. To track anaymously, set it to false. This applies on Analytics module as well.
Example
// 'blt5d4sample2633b' is a dummy Application API key
// When trackAnonymously is set to true logged-in user's info isn't logged for analysis
var app = Built.App('blt5d4sample2633b').setTrackAnonymously(true);

setVersion(version){App}

app.js, line 1110
Sets the version of Built.io Backend you want to communicate to.
Name Type Description
version String The version of Built.io Backend
Example
// 'blt5d4sample2633b' is a dummy Application API key
var app = Built.App('blt5d4sample2633b').setVersion('v2');
console.log(app.getURL())