forked from look/fetcher
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updating docs and changing fetcher api slightly
- Loading branch information
Showing
7 changed files
with
116 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,17 @@ | ||
Fetcher | ||
======= | ||
= Fetcher | ||
|
||
Simplified message fetching | ||
Simplified message fetching | ||
|
||
Install using: | ||
script/plugin install svn://rubyforge.org/var/svn/slantwise/fetcher/trunk | ||
|
||
== Usage | ||
|
||
@fetcher = Fetcher.new(:pop, :server => 'mail.example.com', | ||
:username => 'user', | ||
:password => 'pass', | ||
:reciever => IncomingMailHandler) | ||
loop do | ||
@fetcher.fetch | ||
sleep 60 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
module Fetcher | ||
# Use factory-style initialization or insantiate directly from a subclass | ||
# | ||
# Example: | ||
# | ||
# Fetcher.new(:pop) is equivalent to | ||
# Fetcher::Pop.new() | ||
def self.new(klass, options={}) | ||
module_eval "#{klass.to_s.capitalize}.new(options)" | ||
end | ||
end | ||
|
||
require 'fetcher/base' | ||
require 'fetcher/pop' | ||
require 'fetcher/imap' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,45 @@ | ||
module Fetcher | ||
class Base | ||
|
||
def initialize(options={}) | ||
klass = options.delete(:type) | ||
|
||
if klass | ||
module_eval "#{klass.to_s.capitalize}.new(#{options})" | ||
else | ||
assign_options(options) | ||
%w(server username password receiver).each do |opt| | ||
raise ArgumentError, "#{opt} is required" unless options[opt.to_sym] | ||
instance_eval("@#{opt} = options[:#{opt}]") | ||
end | ||
|
||
end | ||
|
||
|
||
# Run the fetching process | ||
def fetch | ||
establish_connection | ||
get_messages | ||
close_connection | ||
end | ||
|
||
protected | ||
|
||
def assign_options(options={}) | ||
%w(server username password receiver).each do |opt| | ||
instance_eval("@#{opt} = options[:#{opt}]") | ||
end | ||
# Stub. Should be overridden by subclass. | ||
def establish_connection #:nodoc: | ||
raise NotImplementedError, "This method should be overridden by subclass" | ||
end | ||
|
||
def establish_connection | ||
|
||
# Stub. Should be overridden by subclass. | ||
def get_messages #:nodoc: | ||
raise NotImplementedError, "This method should be overridden by subclass" | ||
end | ||
|
||
def get_messages | ||
# Stub. Should be overridden by subclass. | ||
def close_connection #:nodoc: | ||
raise NotImplementedError, "This method should be overridden by subclass" | ||
end | ||
|
||
def close_connection | ||
# Send message to receiver object | ||
def process_message(message) | ||
@receiver.receive(message) | ||
end | ||
|
||
# Stub. Should be overridden by subclass. | ||
def handle_bogus_message(message) #:nodoc: | ||
raise NotImplementedError, "This method should be overridden by subclass" | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters