Jropensocial

From JRapid

Jump to: navigation, search

All Ning apps make an instance of JRapidOpenSocial available, which can be accessed the same way opensocial apps use gadgets or opensocial.

The name of this instance is jropensocial;

Contents

Properties

/* 
 * baseurl  : Base URL declared for the application
 * 
*/

Methods

The following are the methods exposed by jropensocial, and their parameters

/* 
 * postActivity, related to the viewer in the network
 * 
 * text     : text of the activity. Will appear as "<username> textbody".
 * callback : function to be invoked after adding the activity
 */
/* 
 * sendMessage, to other members of the network
 * 
 * subject       : message subject
 * body          : message body
 * target        : "VIEWER", "OWNER", "VIEWER_FRIENDS" (default), "OWNER_FRIENDS" or ids as string in an array.
 * callback(resp): function to manager resp. resp object has  hadError() method to ask if the sendMessage ended normally
 */
/* 
 * getViewer, related to the viewer in the network
 * 
 * callback(id, name): function to be invoked after retrieving viewer data
 */
/*
 * getViewerFull, related to the viewer in the network
 *
 * callback(id, name, profile, thumb): function to be invoked after retrieving viewer data
 */
/* 
 * getOwner, related to the owner of the network
 * 
 * callback(id, name): function to be invoked after retrieving viewer data
 */
/* 
 * getNetwork, related to the network properties
 * 
 * callback(id, subdomain, domains): function to be invoked after retrieving viewer data
 */

Examples

Let's see some examples using the previous methods

jropensocial.sendMessage

This function is used in an action

<action function="share" functionparams="category.name;name;description" label="Share" location="local" name="share" type="javascript"/>

It calls jropensocial.sendMessage with default target (VIEWER_FRIENDS), sending a message with a custom subject and body.

function share(obj, ids, category, name, description) {
	jropensocial.getViewer(function(viewerid,viewername) {
	    jropensocial.sendMessage(viewername + ' wants you to know about an issue regarding ' + category , 
	    		name + ': ' + description); 
	});
};

jropensocial.postActivity and jropensocial.getViewer

This function is used in an action

<action function="worriesMe" functionparams="category.name;name" label="Worries me" location="local" name="worries" type="javascript"/>

It calls jropensocial.postActivity with a custom message. As this message includes viewer name, it needs to call jropensocial.getViewer() first. It also passes a callback function to be called when the activity is posted.

function worriesMe(obj,ids,category,name) {
      jropensocial.getViewer(function(viewerid,viewername) {
           jropensocial.postActivity(viewername + ' worries about about ' + category + ', 
               specifically ' + name, function() {alert('Activity posted');});
 });
};

jropensocial.getOwner and ning.core.getNetworkDomain()

In this function we want to jump to another part of the Ning App. We copy-pasted the URL from the link on top, and replaced network domain and owner Id. We get this information from the network

function jumpToMap() {
  jropensocial.getOwner(function(ownerid,ownername) {
    var url = 'http://' + ning.core.getNetworkDomain() + '/opensocial/ningapps/show?&owner=' + ownerid +
              '&appUrl=http%3A%2F%2Fwww1.jrapidcloud.com%2Fsocialissues-0.1%2Fforms.Main%2FSocialIssue.xml%3Fning-app-status%3Dnetwork' +
              '&view_entity=Issue&view_type=listing&view_listing=gmapList&view_subset=forGmapList&view_subsetparams=network.id';
    top.window.location = url;
  });
}


See Also

  • Ning Ning transformer
Personal tools