Created
October 15, 2009 16:16
-
-
Save febuiles/211062 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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