github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

pluginaweek / has_messages

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 43
    • 4
  • Source
  • Commits
  • Network (4)
  • Downloads (9)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (9)
    • v0.4.0
    • v0.3.1
    • v0.3.0
    • v0.2.0
    • v0.1.3
    • v0.1.2
    • v0.1.1
    • v0.1.0
    • v0.0.1
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Demonstrates a reference implementation for sending messages between users — Read more

  cancel

http://www.pluginaweek.org

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Add gemspec 
obrie (author)
Tue Jun 09 20:32:32 -0700 2009
commit  6046596d5c211eca6a045818862dd2b2b91262ad
tree    bf1e5609f305b93bbeedcb933711ced7dab46074
parent  848e40668eb67670e399dc97f9507fdc46223ce4
has_messages /
name age
history
message
file .gitignore Loading commit data...
file CHANGELOG.rdoc Sun Apr 19 12:47:33 -0700 2009 Tag 0.4.0 release [obrie]
file LICENSE
file README.rdoc
file Rakefile
directory app/
directory db/ Sun Apr 19 12:21:26 -0700 2009 Add dependency on Rails 2.3 Add dependency on p... [obrie]
file has_messages.gemspec Tue Jun 09 20:32:32 -0700 2009 Add gemspec [obrie]
file init.rb Sun Jul 29 14:06:41 -0700 2007 Initial release [obrie]
directory lib/
directory test/ Sun Apr 19 12:21:26 -0700 2009 Add dependency on Rails 2.3 Add dependency on p... [obrie]
README.rdoc

has_messages

has_messages demonstrates a reference implementation for sending messages between users.

Resources

API

  • api.pluginaweek.org/has_messages

Bugs

  • pluginaweek.lighthouseapp.com/projects/13274-has_messages

Development

  • github.com/pluginaweek/has_messages

Source

  • git://github.com/pluginaweek/has_messages.git

Description

Messaging between users is fairly common in web applications, especially those that support social networking. Messaging doesn’t necessarily need to be between users, but can also act as a way for the web application to send notices and other notifications to users.

Designing and building a framework that supports this can be complex and takes away from the business focus. This plugin can help ease that process by demonstrating a reference implementation of these features.

Usage

Adding message support

  class User < ActiveRecord::Base
    has_messages
  end

This will build the following associations:

  • messages
  • unsent_messages
  • sent_messages
  • received_messages

If you have more specific needs, you can create the same associations manually that has_messages builds. See HasMessages::MacroMethods#has_messages for more information about the asssociations that are generated from this macro.

Creating new messages

  message = user.messages.build
  message.to user1, user2
  message.subject = 'Hey!'
  message.body = 'Does anyone want to go out tonight?'
  message.deliver

Replying to messages

  reply = message.reply_to_all
  reply.body = "I'd love to go out!"
  reply.deliver

Forwarding messages

  forward = message.forward
  forward.body = 'Interested?'
  forward.deliver

Processing messages asynchronously

In addition to delivering messages immediately, you can also queue messages so that an external application processes and delivers them. This is especially useful for messages that need to be sent outside of the confines of the application.

To queue messages for external processing, you can use the queue event, rather than deliver. This will indicate to any external processes that the message is ready to be sent.

To process queued emails, you need an external cron job that checks and sends them like so:

  Message.with_state('queued').each do |message|
    message.deliver
  end

Testing

Before you can run any tests, the following gem must be installed:

  • plugin_test_helper

To run against a specific version of Rails:

  rake test RAILS_FRAMEWORK_ROOT=/path/to/rails

Dependencies

  • Rails 2.3 or later
  • state_machine
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server