GithubHelp home page GithubHelp logo

nvdnkpr / activity-streams-mongoose Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ciberch/activity-streams-mongoose

0.0 2.0 0.0 60 KB

Activity Streams Real-Time Data Store backed by MongoDB(via Mongoose) and Redis

License: Apache License 2.0

activity-streams-mongoose's Introduction

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
    • database

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

activity-streams-mongoose's People

Contributors

ciberch avatar joaoneto avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.