Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Streama is a simple activity stream gem for use with the Mongoid ODM framework.
Ruby
Tag: v0.2.0

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

Create an Activity model and define the activities and the fields you would like to cache within the activity.

class Activity

include Streama::Activity

activity :enquiry do
  actor :user, :cache => [:full_name]
  target :enquiry, :cache => [:subject]
  referrer :listing, :cache => [:title]
end

end

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

Setup Indexes

Create the indexes for the Activities collection. You can do so by calling the create_indexes method.

Activity.create_indexes

Publishing Activity

In your controller or background worker:

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

This will publish the activity to the objects returned by the “followers” method in the Actor.

To send your activity to different receievers, pass in an additional :receivers parameter.

current_user.publish_activity(:enquiry, :target => @enquiry, :referrer => @listing, :receivers => :friends) # calls friends method
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)

If you need to return the instance of an :actor, :target or :referrer from an activity call the Activity#load_instance method

activity.load_instance(:actor)

You can also refresh the cached activity data by calling the Activity#refresh_data method

activity.refresh_data

Compatibility

Streama is developed against Ruby 1.9.2 and Mongoid 2.0.0.rc7

TODO

  • Write more documentation, YARD

  • Write more tests

  • Benchmarks

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.