Class: MailFetcher::MailCatcherClient

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_fetcher/mail_catcher_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, clean_inbox = false) ⇒ MailCatcherClient

Returns a new instance of MailCatcherClient.



10
11
12
13
14
15
16
17
18
19
# File 'lib/mail_fetcher/mail_catcher_client.rb', line 10

def initialize(host, port, clean_inbox=false)
  base_url = "http://#{host}:#{port}"
  @connection = Faraday.new base_url do |conn|
    conn.request :json
    conn.response :json, :content_type => /\bjson$/
    conn.use :instrumentation
    conn.adapter Faraday.default_adapter
  end
  delete_all_messages if clean_inbox
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



8
9
10
# File 'lib/mail_fetcher/mail_catcher_client.rb', line 8

def logger
  @logger
end

Instance Method Details

#find(recipient, subject = '', wait = 1) ⇒ Object

Returns MailCatcherMessage if message found or nil.

Returns:

  • MailCatcherMessage if message found or nil



22
23
24
25
26
27
28
# File 'lib/mail_fetcher/mail_catcher_client.rb', line 22

def find(recipient, subject='', wait=1)
  message_id = eventually(:tries => wait, :delay => 1) do
    message_data = all.find { |m| m['recipients'][0].include?(recipient) && m['subject'].include?(subject) }
    message_data ? message_data['id'] : nil
  end
  message_id ? MailCatcherMessage.new(@connection, message_id) : nil
end