Integration Exercise: Mail Servers
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.
- Set up dependencies with
bundle install. You will also need sqlite installed if you don't have it already.
- Fill it in with an e-mail account that you'd like Jester to watch
- Optionally, populate Jester with a few stories by running
- Start Jester by running
Now you can e-mail the address you told him to watch, and use the following 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
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
tell me something funny
Ask for a specific story
tell me '___' - Jester tells you a specific story from his collection
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!
tell something funny to email@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
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
For example, if we wanted to create a greet command:
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