Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 107 lines (79 sloc) 3.208 kB
b3fec74 @practicingruby initial commit
practicingruby authored
1 # Integration Exercise: Mail Servers
f08d9ac @brentvatne Rename project and create initial README
authored
2 ## Jester
92894d4 @brentvatne Set up project skeleton
authored
3 _written by: Brent Vatne_
b3fec74 @practicingruby initial commit
practicingruby authored
4
f08d9ac @brentvatne Rename project and create initial README
authored
5 ## Description and usage
6 Jester is a mail friendly mail daemon that saves a bunch of great
7 stories and jokes and is willing to tell them to anyone who asks. He
c45b946 @brentvatne Improve readme
authored
8 exists in the ethereal realm of email.
9
10 ### Setup
c2eb751 @brentvatne Update readme to mention sqlite
authored
11 1. Set up dependencies with `bundle install`. You will also need sqlite
12 installed if you don't have it already.
13 2. Rename `config/mail_options.example.rb` to `config/mail_options.rb`
14 3. Fill it in with an e-mail account that you'd like Jester to watch
15 4. Optionally, populate Jester with a few stories by running `rake
c45b946 @brentvatne Improve readme
authored
16 sample`
c2eb751 @brentvatne Update readme to mention sqlite
authored
17 5. Start Jester by running `./bin/jester`.
f08d9ac @brentvatne Rename project and create initial README
authored
18
19 Now you can e-mail the address you told him to watch, and use the
20 following commands:
b3fec74 @practicingruby initial commit
practicingruby authored
21
2155868 @brentvatne Fix README formatting
authored
22 ## Commands
c45b946 @brentvatne Improve readme
authored
23
24 Here's a grab bag of everything you can do. Keep in mind that wherever
25 you see quotation marks, they are required.
26
2155868 @brentvatne Fix README formatting
authored
27 ### Add a story
28 `a ____ story 'story name here'` - Teaches Jester a story so he can
b24fc82 @brentvatne Fix formatting of command lists in README and simplify, removing some…
authored
29 share it with others. The story text belongs in the body of the
2155868 @brentvatne Fix README formatting
authored
30 message.
31 <br/><br/>*Example:* `a funny story 'This story is really funny isn't it'`
c45b946 @brentvatne Improve readme
authored
32
2155868 @brentvatne Fix README formatting
authored
33 ### Ask for a random story of a certain type
34 `tell me something __` - Hear a particular kind of story, such as funny
35 <br/><br/>*Example:* `tell me something funny`
c45b946 @brentvatne Improve readme
authored
36
2155868 @brentvatne Fix README formatting
authored
37 ### Ask for a specific story
38 `tell me '___'` - Jester tells you a specific story from his collection
39 <br/><br/>*Example:* `tell me 'What do you call a lazy bear?'`
c45b946 @brentvatne Improve readme
authored
40
2155868 @brentvatne Fix README formatting
authored
41 ### Send a story to a friend
42 `tell something ___ to __@__.__` - Sends a random story to a friend!
43 <br/><br/>*Example:* `tell something funny to you@example.com`
c45b946 @brentvatne Improve readme
authored
44
2155868 @brentvatne Fix README formatting
authored
45 ### List all stories
46 `what stories do you know?` - Lists all of Jester's stories
c45b946 @brentvatne Improve readme
authored
47
2155868 @brentvatne Fix README formatting
authored
48 ### List all commands
49 `help` - List all available commands
c45b946 @brentvatne Improve readme
authored
50
51
4c6624f @brentvatne Fix Readme and clean up Requests
authored
52 ## Add more commands to Jester
0631bb3 @brentvatne Update readme and organize a bit more
authored
53
4c6624f @brentvatne Fix Readme and clean up Requests
authored
54 A command is called a Request in Jester's world. There are two steps to
55 extending Jester's Request repitoire.
56
57 ### 1. Write a new Request class
58
59 Unlike an old dog, it's easy to teach him new tricks. The first step is to
60 create a new Request class in `lib/jester/requests/`, which implements the
61 following interface:
0631bb3 @brentvatne Update readme and organize a bit more
authored
62
51949e8 @brentvatne Add self.description to interface information in readme
authored
63 `self.handle` - returns nil if the message subject is not handled by this
0631bb3 @brentvatne Update readme and organize a bit more
authored
64 request, or an instance of itself if it is handled.
65
51949e8 @brentvatne Add self.description to interface information in readme
authored
66 `self.description` - a text description of how to make the request, and
67 what it does.
68
0631bb3 @brentvatne Update readme and organize a bit more
authored
69 `execute` - performs required actions to carry out the request, returns
70 a `Jester::Request::Response` object
90c2a64 @brentvatne Add example for Jester request
authored
71
4c6624f @brentvatne Fix Readme and clean up Requests
authored
72 For example, if we wanted to create a greet command:
90c2a64 @brentvatne Add example for Jester request
authored
73
74 `lib/jester/requests/greet.rb`
75
76 ```ruby
77 module Jester
78 module Request
79 class Greet
80 def self.handle(message)
81 if message.subject.match(/hello jester/)
82 new(message.from.first)
83 end
84 end
85
86 def self.description
87 "hello jester - Jester will greet you"
88 end
89
90 def initialize(email)
91 @email = email
92 end
93
94 def execute
95 Response.new(:subject => "Well hello world!", :email => @email)
96 end
97 end
98 end
99 end
100 ```
5419914 @brentvatne Explain how to load the request
authored
101
4c6624f @brentvatne Fix Readme and clean up Requests
authored
102 ### 2. Tell the Request handler about it
103
104 The second and final step is to make sure the Request handler knows about your
105 Request object. In `lib/jester/requests.rb`, require your new Request class and
106 add it to the array `VALID_REQUESTS`.
Something went wrong with that request. Please try again.