Giter Site home page Giter Site logo

streama's Introduction

Streama

ALPHA

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

It works by posting to and querying from a firehose of individual activity items.

travis

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.

An activity consists of an actor, a verb, an object, and a target_object.

class Activity
  include Streama::Activity

  activity :new_enquiry do
    actor :user, :cache => [:full_name]
    object :enquiry, :cache => [:subject, :comment]
    target_object :listing, :cache => [:title]
  end

end

The activity verb is implied from the activity name, in the above example the verb is :new_enquiry

The object may be the entity performing the activity, or the entity on which the activity was performed. e.g John(actor) shared a video(object)

The target_object is the object that the verb is enacted on. e.g. Geraldine(actor) posted a photo(object) to her album(target_object)

This is based on the Activity Streams 1.0 specification (http://activitystrea.ms)

Setup Actors

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

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

	field :full_name, :type => String

	def followers
		User.excludes(:id => self.id).all
	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(:new_enquiry, :object => @enquiry, :target_object => @listing)

This will publish the activity to the mongoid 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(:new_enquiry, :object => @enquiry, :target_object => @listing, :receivers => :friends) # calls friends method
current_user.publish_activity(:new_enquiry, :object => @enquiry, :target_object => @listing, :receivers => current_user.find(:all, :conditions => {:group_id => mygroup}))

Retrieving Activity

To retrieve all activity directed to a receiver

current_user.incoming_activity

To retrieve all activity posted by an actor:

current_user.outgoing_activity

To retrieve and filter to a particular activity type

current_user.incoming_activity(:type => :activity_verb)

If you need to return the instance of an :actor, :object or :target_object 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

Contributing

Once you've made your great commits

  1. Fork
  2. Create a topic branch - git checkout -b my_branch
  3. Push to your branch - git push origin my_branch
  4. Create a Pull Request from your branch
  5. That's it!

Contributors

  • Christos Pappas (@christospappas)

streama's People

Contributors

christospappas avatar holgersindbaek avatar pehrlich avatar

Stargazers

 avatar

Watchers

James Cloos 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.