Permalink
Browse files

Fix Readme and clean up Requests

  • Loading branch information...
1 parent 59711d0 commit 4c6624f863c20fef11c06376f59b0dbb66c3340a @brentvatne committed Jan 20, 2012
View
26 README.md
@@ -28,7 +28,10 @@ people looking to brighten up their day.
Of course, some people were born without a funny bone, and have no
desire to read anything funny. Jester thinks that's hilarious, but also
-feels a duty to entertain, so he likes to remember any other type of story too. For example, maybe you heard an interesting fact and that you think Jester and his friends might like to hear. In the subject line of your email put : `an interesting story "why the sky is blue"`
+feels a duty to entertain, so he likes to remember any other type of story too.
+For example, maybe you heard an interesting fact hat you think Jester and his
+friends might like to hear. In the subject line of your email write:
+`an interesting story "why the sky is blue"`
### Ask Jester to brighten up your day
@@ -56,10 +59,16 @@ you see quotation marks, they are required.
`help` - List all available commands
-## Extend Jester
+## Add more commands to Jester
-Unlike an old dog, it's easy to teach him new tricks, just create a request
-class in the `requests` directory, which implements the following interface:
+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.
@@ -70,7 +79,7 @@ what it does.
`execute` - performs required actions to carry out the request, returns
a `Jester::Request::Response` object
-For example, a minimal Jester request could be:
+For example, if we wanted to create a greet command:
`lib/jester/requests/greet.rb`
@@ -100,5 +109,8 @@ module Jester
end
```
-Then in `lib/jester/requests.rb`, require your new Request class and add
-it to the array `VALID_REQUESTS`.
+### 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`.
View
2 lib/jester/incoming_mail_daemon.rb
@@ -31,8 +31,8 @@ def run
# Returns no useful value.
def respond_to_all_new_requests
execute_new_requests.each do |response|
+ output_stream.puts "Sending '#{response.subject}' to #{response.recipient}.."
mail_server.deliver_message(response)
- output_stream.puts "Sending #{response.subject} to #{response.recipient}.."
end
end
View
8 lib/jester/requests.rb
@@ -7,12 +7,8 @@
module Jester
module Request
- VALID_REQUESTS = [ Jester::Request::RememberStory,
- Jester::Request::ListStories,
- Jester::Request::TellToFriend,
- Jester::Request::TellSpecificStory,
- Jester::Request::ListCommands,
- Jester::Request::TellStory ]
+ VALID_REQUESTS = [ RememberStory, ListStories, TellToFriend,
+ TellSpecificStory, ListCommands, TellStory ]
# Delegates execution to one of the valid request classes, otherwise
# sends a request not recognized response.
View
2 lib/jester/requests/list_commands.rb
@@ -2,7 +2,7 @@ module Jester
module Request
class ListCommands
- REQUEST_STRING = /help/i
+ REQUEST_STRING = /^help/i
# Determines whether the message is calling for this request
#
View
2 lib/jester/requests/remember_story.rb
@@ -3,7 +3,7 @@ module Request
class RememberStory
attr_reader :story, :email
- REQUEST_STRING = /^an? (?<type>\w+) story ['"](?<title>[\w\s]+)['"]/i
+ REQUEST_STRING = /^an? (?<type>\w+) story ['"](?<title>[\w\s]+)['"]\s*$/i
# Determines whether the message is calling for this request
#
View
2 lib/jester/requests/tell_specific_story.rb
@@ -3,7 +3,7 @@ module Request
class TellSpecificStory
attr_reader :title, :email
- REQUEST_STRING = /^tell me ['"](?<title>[\w\s]+)['"]/i
+ REQUEST_STRING = /^tell me ['"](?<title>[\w\s]+)['"]\s*$/i
# Determines whether the message is calling for this request
#
View
2 lib/jester/requests/tell_story.rb
@@ -3,7 +3,7 @@ module Request
class TellStory
attr_reader :type, :email
- REQUEST_STRING = /^tell me something (?<type>\w+)/i
+ REQUEST_STRING = /^tell me something (?<type>\w+)\s*$/i
# Determines whether the message is calling for this request
#
View
2 lib/jester/requests/tell_to_friend.rb
@@ -3,7 +3,7 @@ module Request
class TellToFriend
attr_reader :type, :recipient, :sender
- REQUEST_STRING = /^tell something (?<type>\w+) to (?<recipient>[\w\d\._-]+@[\w\d\._-]+)/i
+ REQUEST_STRING = /^tell something (?<type>\w+) to (?<recipient>[\w\d\._-]+@[\w\d\._-]+)\s*$/i
# Determines whether the message is calling for this request
#

0 comments on commit 4c6624f

Please sign in to comment.