class MailFetcher::MailCatcherClient
Attributes
logger[RW]
Public Class Methods
new(host, port, clean_inbox=false)
click to toggle source
# 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
Public Instance Methods
find(recipient, subject='', wait=1)
click to toggle source
@return MailCatcherMessage
if message found or nil
# 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
Private Instance Methods
all()
click to toggle source
# File lib/mail_fetcher/mail_catcher_client.rb, line 36 def all @connection.get('/messages').body end
delete_all_messages()
click to toggle source
# File lib/mail_fetcher/mail_catcher_client.rb, line 32 def delete_all_messages @connection.delete('/messages') end