Skip to content

Commit

Permalink
Update readme and organize a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
brentvatne committed Jan 13, 2012
1 parent 63e0286 commit 0631bb3
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -9,3 +9,4 @@ doc/
.project
.DS_Store
config/mail_options.rb
db/app.db
12 changes: 12 additions & 0 deletions README.md
Expand Up @@ -32,3 +32,15 @@ Great, he can remember jokes that I tell him. What use is a Jester that
you tell jokes to, but that doesn't tell any to you? Ask Jester for a story
by specifying in the subject `tell me something funny` or perhaps `tell
me something interesting`. I'm not judging you, Jester might be.


## Extend Jester

It's easy to teach him new tricks, just create a request class in the
`requests` directory, which implements the following interface:

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

`execute` - performs required actions to carry out the request, returns
a `Jester::Request::Response` object
Binary file modified db/app.db
Binary file not shown.
4 changes: 2 additions & 2 deletions lib/jester.rb
@@ -1,5 +1,5 @@
require_relative 'jester/jester'
require_relative 'jester/mail_server'
require_relative 'jester/incoming_mail_daemon'
require_relative 'jester/model'
require_relative 'jester/request'
require_relative 'jester/models'
require_relative 'jester/requests'
15 changes: 11 additions & 4 deletions lib/jester/incoming_mail_daemon.rb
@@ -1,17 +1,24 @@
class Jester::IncomingMailDaemon
def initialize
def initialize(mail_server = MailServer, request_handler = Request)

end

# def run
# while true
# respond_to_all_new_requests
# sleep(30)
# end
# end

def respond_to_all_new_requests
execute_new_requests.each do |response|
MailServer.deliver_message(response)
mail_server.deliver_message(response)
end
end

def execute_new_requests
MailServer.unread_messages.inject([]) do |responses, message|
responses << Request.execute(message)
mail_server.unread_messages.inject([]) do |responses, message|
responses << request_handler.execute(message)
end
end
end
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions spec/incoming_mail_daemon_spec.rb
@@ -0,0 +1,7 @@
describe Jester::IncomingMailDaemon do

describe "respond_to_all_new_requests" do
let(:daemon) { Jester::IncomingMailDaemon.new }
end

end

0 comments on commit 0631bb3

Please sign in to comment.