Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Streama is a simple activity stream gem for use with the Mongoid ODM framework.
Ruby
tag: v0.1.2

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.document
.gitignore
.rspec
Gemfile
Gemfile.lock
LICENSE.txt
README.rdoc
Rakefile
VERSION
streama.gemspec

README.rdoc

Streama

Streama is a simple Ruby activity stream gem for use with the Mongoid ODM framework.

Install

$ gem install streama

Usage

Define Activities

In an initializer define the activities and the fields you would like to store within the activity.

Streama::Activity.define(:enquiry) do
  actor :user, :store => [:full_name]
  target :enquiry, :store => [:subject]
  referrer :listing, :store => [:title]
end

You do not need to define :_id in the store options as it gets saved automatically.

Setup Actors

Include the Actor module in a class and override the default followers method.

class User
  include Mongoid::Document
  include Streama::Actor

  def followers
    ...
  end
end

You can define multiple activity streams to publish to in your Actor.

The :followers parameter defines the method which returns recipients of the activity.

class User
  include Mongoid::Document
  include Streama::Actor

  activity_stream(:friends, :followers => :friends)
  activity_stream(:family, :followers => :family)

  def friends
    ...
  end

  def family
    ...
  end

end

If you like you can also override the default activity stream follower method

activity_stream(:default, :followers => :your_method)

Publishing Activity

In your controller or background worker:

current_user.publish_activity(:enquiry, :target => @enquiry, :referrer => @listing)

This will send to to the :default stream.

To send your activity to a different stream defined in your actor or a collection of receivers, pass in an additional :receivers parameter.

current_user.publish_activity(:enquiry, :target => @enquiry, :referrer => @listing, :receivers => :friends)
current_user.publish_activity(:enquiry, :target => @enquiry, :referrer => @listing, :receivers => current_user.find(:all, :conditions => {:group_id => mygroup}))

Retrieving Activity

To retrieve all activity for an actor

current_user.activity_stream

To retrieve and filter to a particular activity type

current_user.activity_stream(:type => :activity_type)

You can paginate your results as well

current_user.activity_stream(:page => 1, :per_page => 10)

Compatibility

Streama is developed against Ruby 1.9.2 and Mongoid 2.0.0.rc7

TODO

  • Load an actor, target, referrer instance from an activity once retrieved.

  • Write more documentation, YARD

  • Write more tests

  • Benchmarks

Notes

  • I haven't tested this in production yet. I still need to validate whether the way this gem works is ok.

  • Streama inserts an association record for every recipient of an activity. MongoDB handles thousands of inserts within milliseconds, so it should be able to handle most cases. If storage size is a problem consider using capped collections (Need to test this with mongoid). I'm looking into whether embedding the relation within the actor object is better.

  • If you are looking for something that works with ActiveRecord take a look at fullsailors' activity_stream which inspired this gem.

License

Copyright © 2011 Christos Pappas

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Credits

Christos Pappas: christos dot pappas at gmail dot com

Something went wrong with that request. Please try again.