Author: Monica Wilkinson Copyright (c) 2012 VMware, Inc
Activity Streams is a simple specification used to describe social actions around the web. http://activitystrea.ms
This library provides the following Activity Stream Models on Mongoose:
- ActivityObject
- Activity
For details on the properties each see pne of the following specifications:
- http://activitystrea.ms/specs/json/1.0/
- http://opensocial-resources.googlecode.com/svn/spec/2.0/Social-Data.xml#ActivityEntry
var streamLib = require('activity-streams-mongoose')(options);
// Here you can extend the schemas with any plugins
streamLib.types.UserSchema.plugin(function(schema, options) {
schema.add({ lastMod: {type: Date, default: date}});
});
var asmsDB = new streamLib.DB(streamLib.db, streamLib.types);
var mongoose = require('mongoose');
mongoose.connect(siteConf.mongoUrl);
var streamLib = require('activity-streams-mongoose')(mongoose, options);
var asmsDB = new streamLib.DB(streamLib.db, streamLib.types);
-
mongoUrl --> If you want to let
activity-streams-mongoose
manage Mongoose for you, just pass the url for the MongoDB. Example format ismongodb://localhost/mongodb-asms
-
redis --> Hash including keys specifying connection properties
- host
- port
- pass
- database
Redis is required to be able to publish activities and subscribe to Activity Streams
var cf = new asmsDB.ActivityObject({displayName: "Cloud Foundry" , url: "http://www.cloudfoundry.com"});
cf.save(function (err) {
//...
}
});
var testAct = new asmsDB.Activity({title: "Started the app", target: target._id});
testAct.save(function (err) {
//...
});
Asking for the latest 5 from stream "sfgiants"
asmsDB.Activity.getStream("sfgiants", 5, function (err, docs) {
docs.forEach(function(doc){console.log(doc);});
});
Asking for the latest 5 from firehose
asmsDB.Activity.getFirehose(5, function (err, docs) {
docs.forEach(function(doc){console.log(doc);});
});
var testAct = new asmsDB.Activity({title: "Started the app", target: target._id});
testAct.publish('cloudfoundry-stream');
Note: This will save the activity and then publish it to the stream name
var clientSendFx = function(channel, json) {
io.sockets.in(client.handshake.sid).send(json);
}
asmsDB.Activity.subscribe('cloudfoundry-stream', clientSendFx);
asmsDB.close();
- Start MongoDB
- Start Redis
npm test
Apache License
See LICENSE file for more details