Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Ruby
branch: master

This branch is 55 commits ahead of mendicant-original:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
bin
config
lib
spec
.gitignore
.rspec
.rvmrc.example
Gemfile
Gemfile.lock
README.md
Rakefile
jester.gemspec

README.md

Integration Exercise: Mail Servers

Jester

written by: Brent Vatne

Description and usage

Jester is a mail friendly mail daemon that saves a bunch of great stories and jokes and is willing to tell them to anyone who asks. He exists in the ethereal realm of email.

Setup

  1. Set up dependencies with bundle install. You will also need sqlite installed if you don't have it already.
  2. Rename config/mail_options.example.rb to config/mail_options.rb
  3. Fill it in with an e-mail account that you'd like Jester to watch
  4. Optionally, populate Jester with a few stories by running rake sample
  5. Start Jester by running ./bin/jester.

Now you can e-mail the address you told him to watch, and use the following commands:

Commands

Here's a grab bag of everything you can do. Keep in mind that wherever you see quotation marks, they are required.

Add a story

a ____ story 'story name here' - Teaches Jester a story so he can share it with others. The story text belongs in the body of the message.

Example: a funny story 'This story is really funny isn't it'

Ask for a random story of a certain type

tell me something __ - Hear a particular kind of story, such as funny

Example: tell me something funny

Ask for a specific story

tell me '___' - Jester tells you a specific story from his collection

Example: tell me 'What do you call a lazy bear?'

Send a story to a friend

tell something ___ to __@__.__ - Sends a random story to a friend!

Example: tell something funny to you@example.com

List all stories

what stories do you know? - Lists all of Jester's stories

List all commands

help - List all available commands

Add more commands to Jester

A command is called a Request in Jester's world. There are two steps to extending Jester's Request repitoire.

1. Write a new Request class

Unlike an old dog, it's easy to teach him new tricks. The first step is to create a new Request class in lib/jester/requests/, which implements the following interface:

self.handle - returns nil if the message subject is not handled by this request, or an instance of itself if it is handled.

self.description - a text description of how to make the request, and what it does.

execute - performs required actions to carry out the request, returns a Jester::Request::Response object

For example, if we wanted to create a greet command:

lib/jester/requests/greet.rb

module Jester
  module Request
    class Greet
      def self.handle(message)
        if message.subject.match(/hello jester/)
          new(message.from.first)
        end
      end

      def self.description
        "hello jester - Jester will greet you"
      end

      def initialize(email)
        @email = email
      end

      def execute
        Response.new(:subject => "Well hello world!", :email => @email)
      end
    end
  end
end

2. Tell the Request handler about it

The second and final step is to make sure the Request handler knows about your Request object. In lib/jester/requests.rb, require your new Request class and add it to the array VALID_REQUESTS.

Something went wrong with that request. Please try again.