Class: Fetcher::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/fetcher/base.rb

Direct Known Subclasses

Imap

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Options:

  • :server - Server to connect to.

  • :username - Username to use when connecting to server.

  • :password - Password to use when connecting to server.

  • :receiver - Receiver object to pass messages to. Assumes the

receiver object has a receive method that takes a message as it’s argument

Additional protocol-specific options implimented by sub-classes

Example:

Fetcher::Base.new(:server => 'mail.example.com',
                  :username => 'pam',
                  :password => 'test',
                  :receiver => IncomingMailHandler)


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fetcher/base.rb', line 17

def initialize(options={})
  %w(server username password receiver).each do |opt|
    raise ArgumentError, "#{opt} is required" unless options[opt.to_sym]
    # convert receiver to a Class if it isn't already.
    if opt == "receiver" && options[:receiver].is_a?(String)
      options[:receiver] = Kernel.const_get(options[:receiver])
    end
      
    instance_eval("@#{opt} = options[:#{opt}]")
  end
end

Instance Method Details

#fetchObject

Run the fetching process



30
31
32
33
34
# File 'lib/fetcher/base.rb', line 30

def fetch
  establish_connection
  get_messages
  close_connection
end