Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding activitystreams module

  • Loading branch information...
commit 0b5045a2cef6712f78bdeaf5651ad6949da2fb91 1 parent 1e5d740
@maxogden authored
View
1  .gitignore
@@ -0,0 +1 @@
+.DS_Store
View
73 src/jactivitystream.js
@@ -0,0 +1,73 @@
+function JActivityStream(xml) {
+ this._parse(xml);
+};
+
+JActivityStream.prototype = {
+
+ _parse: function(xml) {
+
+ var channel = jQuery(jQuery('feed', xml).eq(0));
+
+ this.version = '1.0';
+ this.title = channel.find('title').eq(0).text();
+ this.link = channel.find('link').eq(0).attr('href');
+ this.description = channel.find('subtitle').eq(0).text();
+ this.language = channel.attr('xml:lang');
+ this.updated = channel.find('updated').eq(0).text();
+
+ this.items = new Array();
+
+ var feed = this;
+
+ jQuery('entry', xml).each( function() {
+
+ var entry = jQuery(this);
+ var baseIRI = 'http://activitystrea.ms/schema/1.0/';
+
+ function clean(text) {
+ return text.replace(baseIRI, '')
+ .replace(/\n/g,'') // newlines
+ .replace(/^[ \t]+/g,'') // leading whitespace
+ .replace(/[ \t]+$/g,''); // trailing whitespace
+ }
+
+ function grab(attr, scope, text) {
+ entry = scope ? scope : entry;
+ text = typeof(text) === "undefined" ? true : text;
+ var node = entry.find(attr).eq(0);
+ if (text) {
+ return clean(node.text());
+ } else {
+ // returns the first jquery node instead of the text
+ return node;
+ }
+ }
+
+ var item = {
+ title: grab('title'),
+ link: grab('link', false, false).attr('href'),
+ description: grab('content'),
+ updated: grab('updated'),
+ id: grab('id'),
+ author: grab('author name', channel),
+ verb: grab('[nodeName="activity:verb"]')
+ }
+
+ var object = entry.find('[nodeName="activity:object"]');
+ item.object = {
+ id: grab('id', object),
+ title: grab('title', object),
+ link: grab('link', false, false).attr('href'),
+ published: grab('published', object),
+ "object-type": grab('[nodeName="activity:object-type"]', object),
+ source: {
+ title: grab('source title', object),
+ link: grab('source link', false, false).attr('href')
+ }
+ }
+
+ feed.items.push(item);
+ });
+ }
+};
+
View
9 src/jfeed.js
@@ -61,9 +61,14 @@ JFeed.prototype = {
var feedClass = new JRss(xml);
} else if (jQuery('feed', xml).length == 1) {
-
+ var activityStream = jQuery('feed:first', xml).attr('xmlns:activity');
+ if (activityStream && activityStream === "http://activitystrea.ms/spec/1.0/") {
+ this.type = 'activityStream';
+ var feedClass = new JActivityStream(xml);
+ } else {
this.type = 'atom';
- var feedClass = new JAtom(xml);
+ var feedClass = new JAtom(xml);
+ }
}
if (feedClass) jQuery.extend(this, feedClass);
View
50 xml/activitystream.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Author: Ade Oshineye
+-->
+<!--
+ Description: Example atom feed with an activity stream embedded
+-->
+<feed xmlns="http://www.w3.org/2005/Atom"
+ xmlns:activity="http://activitystrea.ms/spec/1.0/">
+ <title>Example Feed</title>
+ <subtitle>example data</subtitle>
+ <link href="http://example.org/"/>
+ <updated>2003-12-13T18:30:02Z</updated>
+ <author>
+ <name>John Doe</name>
+ </author>
+ <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
+<entry>
+ <id>tag:photopanic.example.com,2008:activity01</id>
+ <title>Geraldine posted a Photo on PhotoPanic</title>
+ <published>2008-11-02T15:29:00Z</published>
+ <updated>2009-07-28T11:00:00Z</updated>
+ <link rel="alternate" type="text/html"
+ href="http://example.com/geraldine/activities/1" />
+ <activity:verb>
+ http://activitystrea.ms/schema/1.0/post
+ </activity:verb>
+ <activity:object>
+ <id>tag:photopanic.example.com,2008:photo01</id>
+ <title>My Cat</title>
+ <published>2008-11-02T15:29:00Z</published>
+ <link rel="alternate" type="text/html"
+ href="http://example.com/geraldine/photos/1" />
+ <activity:object-type>
+ tag:atomactivity.example.com,2008:photo
+ </activity:object-type>
+ <source>
+ <title>Geraldine's Photos</title>
+ <link rel="self" type="application/atom+xml"
+ href="http://example.com/geraldine/photofeed.xml" />
+ <link rel="alternate" type="text/html"
+ href="http://example.com/geraldine/" />
+ </source>
+ </activity:object>
+ <content type="html">
+ &lt;p&gt;Geraldine posted a Photo on PhotoPanic&lt;/p&gt;
+ &lt;img src="/geraldine/photo1.jpg"&gt;
+ </content>
+</entry>
+</feed>
Please sign in to comment.
Something went wrong with that request. Please try again.