X
X

Login

Login if you already have an account

LOGIN

Register

Create a new account. join us!

REGISTER

Support

Need some help? Check out our forum.

FORUM

FYI – it is easy to integrate your backend with other web services (for example, SalesForce.com)

As a Developer, I want to integrate with other web services so that I can offload the integration point from my client code to my backend for better performance, security and reliablility.

Many times, you may want to utilize some other web service for the purposes of backend integration. FatFractal makes this really easy. FatFractal supports the Common.js standard which includes an http client that let’s you do just about anything you want.

Let’s say you want to interact with SalesForce data from your backend…

Example:

Here is some code that securely retrieves some information from a SalesForce API that could be used in either a Server Extension of Event Handler:

var hc = require('ringo/httpclient');

exports.getQs = function() {
var loginUrl = "https://login.salesforce.com/services/oauth2/token";
var apiVersion = "v25.0";
var username = "someUsername";
var password = "somePassword";
var securityToken = "someSecurityToken";
var clientId = "someClientId";
var clientSecret = "someClientSecret";

function LoginSF(username, password, securityToken, clientId, clientSecret) {
var data = {
grant_type: "password",
client_id: clientId,
client_secret: clientSecret,
username: username,
password: password + securityToken
};
var response = JSON.parse(hc.post(loginUrl, data).content);
return response;
}

function QuerySF(instanceUrl, accessToken, queryString) {
var url = instanceUrl + "/services/data" + apiVersion + "/query";
var data = {q: queryString};

var request = {
url: url,
data: data,
method: "GET",
headers: {
Authorization: "Bearer " + accessToken
}
};

var response = JSON.parse(hc.request(request).content);
return response;
}
// perform query
var loginResponse = LoginSF(username, password, securityToken, clientId, clientSecret, true);
var instanceUrl = loginResponse.instance_url;
var accessToken = loginResponse.access_token;
var queryResponse = QuerySF(instanceUrl, accessToken, "SELECT A__c, B__c, C__c FROM D__c");

var records = queryResponse.records;
for (var i = 0; i < records.length; i++) {
// DO SOME STUFF
// E.G. RETURN SOME DATA (SERVER EXTENSION)
// OR TAKE SOME ACTION (EVENT HANDLER)
}
}

Note the inclusion of the httpclient at the top of the source:

var hc = require('ringo/httpclient');

The rest defines a function – “getQs” that can be used with an Event Handler or as an Server Extension that logs in to an API on SalesForce.com, retrieves an instance_url and access_token that are required to then to execute a query and retrieve a response.

Many other things can be done with this powerful client – have fun!

For more information on our Server-Side Javascript SDK, see here.

For more information on Event Handlers on your backend, see here.

For more information on Server Extensions on your backend, see here.

Kevin

FYI – Permissions can be inherited from other objects (pretty slick!)

As a Developer, I want to be able to implement access control policies that are inherited from another object so that I can easily propagate access control policies within my application.

If you want to set a default permission for objects in a collection that inherit permissions from another object, it is super easy using FFDL (what is FFDL?).

Example:

Say you have a Collection of JokeBook objects with permission defaults set and another Collection of Joke objects that have a reference to a JokeBook and you would like your Joke objects to inherit their default permissions from JokeBook objects. OK – short version is that I want the permissions for a Joke to be the same as the JokeBook they refer to.

The FFDL would look something like:

# JokeBook
CREATE OBJECTTYPE JokeBook (title STRING, writers REFERENCE /FFUserGroup, readers REFERENCE /FFUserGroup)
CREATE COLLECTION /JokeBooks OBJECTTYPE JokeBook
PERMIT read:object.readers write:object.writers ON /JokeBooks

This defines a JokeBooks Collection that contains Jokebook Objects that have a title, a reference to an author, a reference to a group of users with write access named writers and a group of users with read access named readers.

# Joke
CREATE OBJECTTYPE Joke (setup STRING, punchline STRING, book REFERENCE /JokeBook)
CREATE COLLECTION /Jokes OBJECTTYPE Joke
PERMIT read:object.book.readers write:object.book.writers ON /Jokes

This defines a Jokes Collection that contains Joke Objects which have a a reference called “book” from the JokeBooks Collection:

book REFERENCE /JokeBooks
So, you will notice that read and write permissions for a Joke object are set to refer to the read and write permissions (respectively) that are defined for the JokeBook object referred to by the “book” member.

PERMIT read:object.book.readers, write:object.book.writers ON /Jokes

Voila! Now the Joke object has the same permissions as the JokeBook object – as easy as that!

Of course, this is the default setting and you can always change the access to any particular object programmatically in your application code.

Hope you find this useful!!

For more details, see the FFDL documentation here.

To see the other things you can do with permissions see here.

Contact