Skip to content

Instantly share code, notes, and snippets.

@febuiles
Created October 15, 2009 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save febuiles/211062 to your computer and use it in GitHub Desktop.
Save febuiles/211062 to your computer and use it in GitHub Desktop.
// Sends a user's friends to the server
function save_people() {
var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.OWNER), "owner");
var owner_friends = new opensocial.IdSpec();
owner_friends.setField(opensocial.IdSpec.Field.USER_ID, opensocial.IdSpec.PersonId.OWNER);
owner_friends.setField(opensocial.IdSpec.Field.GROUP_ID, 'FRIENDS');
owner_friends.setField(opensocial.IdSpec.Field.NETWORK_DISTANCE, 1);
req.add(req.newFetchPeopleRequest(owner_friends, {}), "owner_friends");
$.blockUI();
req.send(
function (data) {
var owner = data.get("owner").getData();
var friends = [ { name : owner.getDisplayName(),
photo: owner.getField(opensocial.Person.Field.THUMBNAIL_URL),
uid : owner.getId()} ];
var owner_friends = data.get('owner_friends').getData();
owner_friends.each(function(friend){
friends.push({ name : friend.getDisplayName(),
photo : friend.getField(opensocial.Person.Field.THUMBNAIL_URL),
uid: friend.getId() });
});
post("http://murano.mentez.com/users",
{ users : $.toJSON(friends) },
function(response) {
if (response.rc == 200) {
$.unblockUI();
create_friendships(friends);
} else {
$.unblockUI();
$("#error_message").show();
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment