Inkwell adds social networking features – comments, reblogs, favorites, ability to follow other people and view their timeline.
Pull request Compare This branch is 130 commits behind salkar:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
app
config
db/migrate
lib
script
test/dummy
.gitignore
Gemfile
MIT-LICENSE
README.rdoc
Rakefile
inkwell.gemspec

README.rdoc

Inkwell

Inkwell provides simple way to add social networking features like comments, reblogs, favorites, following/followers, timelines to your Ruby on Rails application

Requirements

You should have two classes: User and Post or other identical. Between them should be a one-to-many relationship. For example:

class User < ActiveRecord::Base
  has_many :posts
end

class Post < ActiveRecord::Base
  belongs_to :user
end

Installation

Put in Gemfile:

gem 'inkwell', :git => 'git://github.com/salkar/inkwell.git'

After it do bundle install

Add to your User model acts_as_inkwell_user and to your Post model acts_as_inkwell_post

class User < ActiveRecord::Base
  has_many :posts
  acts_as_inkwell_user
end

class Post < ActiveRecord::Base
  belongs_to :user
  acts_as_inkwell_post
end

Create inkwell.rb file in config/initializers and put in it your names of User and Post tables (or other identical):

module Inkwell
  class Engine < Rails::Engine
    config.post_table = :posts
    config.user_table = :users
  end
end

Next, get gem migrations:

rake inkwell:install:migrations

and db:migrate it.

Usage

Favorite features

User is able to favorite posts/comments:

@user.favorite @post
@user.favorite @comment

For delete post/comment from favorites you should do:

@user.unfavorite @post

For check that post/comment enters in favorites you should do:

@user.favorite? @post

For return favorite line, consisting of favorited posts and comments, you should do:

@user.favoriteline(last_shown_obj_id = nil, limit = 10, for_user = nil)

where

  • last_shown_obj_id - id of the last item in favorite line shown to the user. Get it from item_id_in_line property of last item from previous favoriteline calls. This parameter is for pagination and separation of the timeline.

    fline = @user.favoriteline    #get first 10 items from @user favorite line
    last_shown_obj_id = fline.last.item_id_in_line
    fline_next_page = @user.favoriteline last_shown_obj_id    #get next 10 items from @user favorite line
  • limit - number of returned favorited items

    fline = @user.favoriteline nil, 20    #return first 20 items from @user favorite line
  • for_user - User, who looks this favorite line. For him is_reblogged and is_favorited properties will been formed.

    @user.favorite @another_user_post
    @user.reblog @another_user_post
    
    fline_for_unknown_user = @another_user.favoriteline nil, 10, nil
    # For example, fline_for_unknown_user.first == @another_user_post
    fline_for_unknown_user.first.is_reblogged    # => false
    fline_for_unknown_user.first.is_favorited    # => false
    
    fline_for_user_who_reblog_and_favorite_another_user_post = @another_user.favoriteline nil, 10, @user
    # For example, fline_for_user_who_reblog_and_favorite_another_user_post.first == @another_user_post
    fline_for_user_who_reblog_and_favorite_another_user_post.first.is_reblogged    # => true
    fline_for_user_who_reblog_and_favorite_another_user_post.first.is_favorited    # => true

More examples you can find in this spec.

Reblog features

Reblog means that reblogged post will be added to user's blogline and to timelines of his followers. Thus, the behavior of reblogged object is similar to the post of the user who made this reblog. User is able to reblog posts/comments:

@user.reblog @post
@user.reblog @comment

For delete post/comment from reblogs you should do:

@user.unreblog @post

For check that post/comment enters in reblogs you should do:

@user.reblog? @post

Reblogs don't have their own line and are contained in user's blogline.

More examples you can find in this spec.

Comment features

User is able to create comments for post or other comment. If you want to comment the post you should do:

@user.comments.create :post_id => @post.id, :body => "comment_body"

If you want to comment other comment you should add parent_id of parent comment:

@user.comments.create :post_id => @parent_post.id, :body => "comment_body", :parent_id => @parent_comment.id

For delete comment you should use destroy method:

@comment.destroy

You are able to get comment line for post or comment. It consists of comments for this object in reverse chronological order.

Notice: returned array will have back order to simplify the use. Last comment is at the bottom usually.

For get comment line you should do:

commentline(last_shown_comment_id = nil, limit = 10, for_user = nil)

where last_shown_comment_id is id of last shown comment from previous commentline results. For example:

cline = @post.commentline    #get last 10 comments for @post
last_shown_comment_id = cline.first.id    # First element is taken due to reverse order. In fact, it is the oldest of these comments.
cline_next_page = @post.commentline last_shown_comment_id

Limit and for_user mean the same thing as in the favoriteline.

More examples you can find in this spec.

Follow features

User is able to follow another user. It allows him to get followed user's blogline in his timeline.

For follow user you should do:

@user.follow @another_user

After it last 10 @another_user blogline's items will be transferred to @user timeline. And each new @another_user blogline item will be added to @user timeline

For unfollow user you should do:

@user.unfollow @another_user

For check that user is follower of another user you should do:

@user.follow? @another_user

For get followers ids for user and ids of users, which he follow, you should do:

@user.followers_row
@user.followings_row

Both methods return arrays of ids.

More examples you can find in this spec.

Blogline feature

User blogine is consists of his posts and his reblogs. For get it you should do:

@user.blogline(last_shown_obj_id = nil, limit = 10, for_user = nil)

where parameters are similar with described above favoriteline parameters.

More examples you can find in this spec.

Timeline feature

User timeline is consists of items from bloglines of users, which he follow. For get it you should do:

@user.timeline(last_shown_obj_id = nil, limit = 10, for_user = nil)

where parameters are similar with described above favoriteline parameters.

More examples you can find in this spec.