Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

activity-streams-mongoose

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

activity-streams-mongoose

Activity Streams Engine using MongoDB(Mongoose odm) and Redis

  • 0.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

build status

Author: Monica Wilkinson Copyright (c) 2012 VMware, Inc

Overview

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:

Usage

Implicit

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);

Or explicit if you need a Mongoose reference in your calling code

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);

Options

  • mongoUrl --> If you want to let activity-streams-mongoose manage Mongoose for you, just pass the url for the MongoDB. Example format is mongodb://localhost/mongodb-asms

  • redis --> Hash including keys specifying connection properties

    • host
    • port
    • pass

Redis is required to be able to publish activities and subscribe to Activity Streams

To create an activity object you can do

var cf = new asmsDB.ActivityObject({displayName: "Cloud Foundry" , url: "http://www.cloudfoundry.com"});
cf.save(function (err) {
    //...
    }
});

To create an activity with an associated activity object you can do


var testAct = new asmsDB.Activity({title: "Started the app", target: target._id});
testAct.save(function (err) {
    //...
});

To query the Activity Streams do

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);});
});

To publish an activity you can do


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

To subscribe to an Activity Stream do

var clientSendFx =  function(channel, json) {
            io.sockets.in(client.handshake.sid).send(json);
        }

asmsDB.Activity.subscribe('cloudfoundry-stream', clientSendFx);

To close the Activity Stream DB connections (MongoDB and Redis)

asmsDB.close();

To run tests

  • Start MongoDB
  • Start Redis
npm test

License

Apache License

See LICENSE file for more details

FAQs

Package last updated on 13 Sep 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc