You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by li...@apache.org on 2010/07/02 02:50:07 UTC

svn commit: r959823 - in /shindig/trunk/content/samplecontainer/examples/ActivityStreams: ActivityStreamsRender.js OpenSocialWrapper.js

Author: lindner
Date: Fri Jul  2 00:50:06 2010
New Revision: 959823

URL: http://svn.apache.org/viewvc?rev=959823&view=rev
Log:
SHINDIG-1329 | Updates to ActivityStream support

Added:
    shindig/trunk/content/samplecontainer/examples/ActivityStreams/ActivityStreamsRender.js
    shindig/trunk/content/samplecontainer/examples/ActivityStreams/OpenSocialWrapper.js

Added: shindig/trunk/content/samplecontainer/examples/ActivityStreams/ActivityStreamsRender.js
URL: http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/ActivityStreams/ActivityStreamsRender.js?rev=959823&view=auto
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/ActivityStreams/ActivityStreamsRender.js (added)
+++ shindig/trunk/content/samplecontainer/examples/ActivityStreams/ActivityStreamsRender.js Fri Jul  2 00:50:06 2010
@@ -0,0 +1,116 @@
+function ActivityStreamsRender() {
+
+	// Private member that wraps the OpenSocial API
+	var social = new OpenSocialWrapper();
+	
+	// =================== PUBLIC ====================
+
+	// Renders the welcome text (viewer, owner, and friends)
+	this.renderWelcome = function(div, callback) {
+		social.loadPeople(function(response) {
+			viewer = response.viewer;
+			owner = response.owner;
+			var viewerFriends = response.viewerFriends;
+			var ownerFriends = response.ownerFriends;
+			
+			var html = "<h1>Welcome " + viewer.name.formatted + "!</h1>";
+			html += "You are viewing " + owner.name.formatted + "'s data. <br><br>";
+			html += "Here is a list of your friends: <br>";
+			html += "<lu>";
+			for(i = 0; i < viewerFriends.list.length; i++) {
+				html += "<li>" + viewerFriends.list[i].name.formatted + "</li>";
+			}
+			html += "</lu>";
+			document.getElementById(div).innerHTML = html;
+			callback();
+		});
+	}
+	
+	// Renders the activities
+	this.renderActivities = function(div, callback) {
+		social.loadActivities(function(response) {
+			var viewerActivities = response.viewerActivities.list;
+			var ownerActivities = response.ownerActivities.list;
+			var friendActivities = response.friendActivities.list;
+			
+			var html = "<h1>Activities</h1>";
+			html += "Demonstrates use of the Activities service in Apache Shindig.  The ActivityStreams service does not interfere with this service.<br><br>";
+			html += "Activities for you and " + owner.name.formatted + ":<br>";
+			html += "<table border='1'>";
+			html += "<tr>";
+			html += "<td>Name</td>";
+			html += "<td>Title</td>";
+			html += "<td>Body</td>";
+			html += "<td>Images</td>";
+			html += "</tr>"
+			html += processActivities(viewerActivities);
+			html += processActivities(ownerActivities);
+			html += processActivities(friendActivities);
+			html += "</table>";
+			document.getElementById(div).innerHTML = html;
+			callback();
+		});
+	}
+	
+	// Renders activity entries
+	this.renderActivityEntries = function(div, callback) {
+		social.loadActivityEntries(function(response) {
+			var html = '';
+			viewerEntries = response.viewerEntries.list;
+			ownerEntries = response.ownerEntries.list;
+			friendEntries = response.friendEntries.list;
+			html = "<h2>ActivityEntries</h2>";
+			html += processActivityEntries(viewerEntries);
+			html += processActivityEntries(ownerEntries);
+			html += processActivityEntries(friendEntries);
+			if (viewerEntries.length + ownerEntries.length + friendEntries.length == 0) {
+				html += "<tr><td>No entries to show!</td></tr>";
+			}
+			html += "</table><br><br>";
+			document.getElementById(div).innerHTML = html;
+			callback();
+		});
+	}
+	
+	// ================== PRIVATE =====================
+	
+	// Processes activities and returns the rendered HTML
+	function processActivities(activities) {
+		var html = '';
+		for(idx = 0; idx < activities.length; idx++) {
+			html += "<tr>";
+			html += "<td>" + activities[idx].userId + "</td>";
+			html += "<td>" + activities[idx].title + "</td>";
+			html += "<td>" + activities[idx].body + "</td>";
+			var mediaItems = activities[idx].mediaItems;
+			if(mediaItems != null) {
+				for(itemIdx = 0; itemIdx < mediaItems.length; itemIdx++) {
+					if(mediaItems[itemIdx].type == "image") {
+						html += "<td><img src='" + mediaItems[itemIdx].url + "' width=150 height=150/></td>";
+					}
+				}
+			}
+			html += "</tr>";
+		}
+		return html;
+	}
+	
+	// Processes activity entries and returns the rendered HTML
+	function processActivityEntries(entries) {
+		var html = '';
+		for(idx = 0; idx < entries.length; idx++) {
+			if(entries[idx].object.permalink && entries[idx].object.permalink != "null") {
+				html += "<h3><a href='" + entries[idx].object.permalink + "'>" + entries[idx].title + "</a></h3>";
+			} else {
+				html += "<h3>" + entries[idx].title + "</h3>";
+			}
+			html += "ID: " + entries[idx].object.id + "<br>";
+			html += "Actor: " + entries[idx].actor.name + "<br>";
+			html += "Posted: " + entries[idx].time + "<br>";
+			if(entries[idx].body && entries[idx].body != "null") {
+				html += "Body: " + entries[idx].body + "<br>";
+			}
+		}
+		return html;
+	}
+}
\ No newline at end of file

Added: shindig/trunk/content/samplecontainer/examples/ActivityStreams/OpenSocialWrapper.js
URL: http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/ActivityStreams/OpenSocialWrapper.js?rev=959823&view=auto
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/ActivityStreams/OpenSocialWrapper.js (added)
+++ shindig/trunk/content/samplecontainer/examples/ActivityStreams/OpenSocialWrapper.js Fri Jul  2 00:50:06 2010
@@ -0,0 +1,146 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+function OpenSocialWrapper() {
+	
+	// =============================== PEOPLE ===============================
+	
+	/*
+	 * Loads the owner, the viewer, the owner's friends, and the viewer's
+	 * friends.  Response data is put into the variables owner, viewer,
+	 * ownerFriends, and viewerFriends, respectively.
+	 * 
+	 * @param callback is the function to return the response to
+	 */
+	this.loadPeople = function(callback) {
+		var batch = osapi.newBatch();
+		batch.add('viewer', osapi.people.getViewer());
+		batch.add('owner', osapi.people.getOwner());
+		batch.add('viewerFriends', osapi.people.getViewerFriends());
+		batch.add('ownerFriends', osapi.people.getOwnerFriends());
+		batch.execute(callback);
+	}
+	
+	this.loadViewerFriends = function(callback) {
+		osapi.people.getViewerFriends().execute(callback);
+	}
+	
+	this.loadOwnerFriends = function(callback) {
+		osapi.people.getOwnerFriends().execute(callback);
+	}
+	
+	// ========================= ACTIVITIES =============================
+	this.loadActivities = function(callback) {
+		var batch = osapi.newBatch();
+		batch.add('viewerActivities', osapi.activities.get({userId: '@viewer', groupId: '@self'}));
+		batch.add('ownerActivities', osapi.activities.get({userId: '@owner', groupId: '@self'}));
+		batch.add('friendActivities', osapi.activities.get({userId: '@viewer', groupId: '@friend'}));
+		batch.execute(callback);
+	}
+	
+	this.loadViewerActivities = function(callback) {
+		var req = osapi.activities.get({userId: '@viewer', groupId: '@self'});
+		req.execute(callback);
+	}
+	
+	this.loadViewerFriendsActivities = function(callback) {
+		var req = osapi.activities.get({userId: '@viewer', groupId: '@friends'});
+		req.execute(this.onLoadActivitiesFriends);
+	}
+	
+	this.loadOwnerActivities = function(callback) {
+		var req = osapi.activities.get({userId: '@owner', groupId: '@self'});
+		req.execute(callback);
+	}
+
+	
+	// ========================= ACTIVITY STREAMS =============================
+	this.loadActivityEntries = function(callback) {
+		var batch = osapi.newBatch();
+		batch.add('viewerEntries', osapi.activitystreams.get({userId: '@viewer', groupId: '@self'}));
+		batch.add('ownerEntries', osapi.activitystreams.get({userId: '@owner', groupId: '@self'}));
+		batch.add('friendEntries', osapi.activitystreams.get({userId: '@viewer', groupId: '@friend'}));
+		batch.execute(callback);
+	}
+	
+	this.loadViewerActivityEntries = function(callback) {
+		var params = {userId: '@viewer', groupId: '@self'}
+		osapi.activitystreams.get(params).execute(callback);
+	}
+	
+	this.loadOwnerActivityEntries = function(callback) {
+		var params = {userId: '@owner', groupId: '@self'}
+		osapi.activitystreams.get(params).execute(callback);
+	}
+	
+	this.loadViewerFriendsActivityEntries = function(callback) {
+		var params = {userId: '@viewer', groupId: '@friends'}
+		osapi.activitystreams.get(params).execute(callback);
+	}
+	
+	this.postActivityEntry = function(title, body, standardLink, verbs, actorId, actorName, objectName, objectSummary,
+									  objectImage, objectPermalink, objectTypes, callback) { 
+		var params = {
+			userId: '@viewer',
+			groupId: '@self',
+			activityEntry: {
+				standardLink: [standardLink],
+				time: '2010-04-27T06:02:36+0000',
+				title: title,
+				body: body,
+				actor: {
+					id: actorId,
+					name: actorName
+				},
+				verb: verbs,
+				object: {
+					id: 'entryId123',
+					name: objectName,
+					permalink: objectPermalink,
+					type: objectTypes,
+					media: {
+						target: 'http://myvideos.com/raftingtrip/raftingvideo.avi',
+						type: 'http://activitystrea.ms/schema/1.0/video',
+						width: '400',
+						height: '300',
+						duration: '93'
+					},
+					action: {
+						target: 'http://myvideos.com/raftingvideo',
+						caption: 'Went white water rafting in the great lakes - ga hah!'
+					}
+				}
+			}
+		}
+		osapi.activitystreams.create(params).execute(callback);
+	}
+	
+	this.deleteActivityEntryById = function(activityEntryId, callback) {
+		var params = {
+			userId: '@viewer',
+			groupId: '@self',
+			activityEntryId: activityEntryId
+		}
+		osapi.activitystreams.delete(params).execute(callback);
+	}
+	
+	this.getActivityEntryById = function(activityEntryId, callback) {
+		var params = {activityEntryId: activityEntryId};
+		osapi.activitystreams.get(params).execute(callback);
+	}
+}
\ No newline at end of file