Class: Cucumber::Mailcatcher::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/mailcatcher/api.rb

Instance Method Summary collapse

Constructor Details

#initialize(http_client) ⇒ Api

Returns a new instance of Api.



4
5
6
# File 'lib/cucumber/mailcatcher/api.rb', line 4

def initialize http_client
  @http = http_client
end

Instance Method Details

#delete_messagesObject



54
55
56
57
# File 'lib/cucumber/mailcatcher/api.rb', line 54

def delete_messages
  @http.do_delete '/messages'
  true
end

#get_messagesObject



8
9
10
# File 'lib/cucumber/mailcatcher/api.rb', line 8

def get_messages
  @http.do_get_json '/messages'
end

#get_messages_from_email(email) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/cucumber/mailcatcher/api.rb', line 12

def get_messages_from_email email
  messages = get_messages

  messages.select { |item|
    item if item["sender"].include?(email)
  }
end

#get_messages_to_email(email) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/cucumber/mailcatcher/api.rb', line 20

def get_messages_to_email email
  messages = get_messages

  messages.select { |item|
    item if item["recipients"].include?(email) || item["recipients"].include?('<' + email + '>')
  }
end

#get_messages_with_html_body(body) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/cucumber/mailcatcher/api.rb', line 36

def get_messages_with_html_body body
  messages = get_messages

  messages.select { |item|
    response = @http.do_get "/messages/#{item['id']}.json.html"
    item if response.code != '404' && response.body.include?(body)
  }
end

#get_messages_with_plain_body(body) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/cucumber/mailcatcher/api.rb', line 45

def get_messages_with_plain_body body
  messages = get_messages

  messages.select { |item|
    response = @http.do_get "/messages/#{item['id']}.json.plain"
    item if response.code != '404' && response.body.include?(body)
  }
end

#get_messages_with_subject(subject) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/cucumber/mailcatcher/api.rb', line 28

def get_messages_with_subject subject
  messages = get_messages

  messages.select { |item|
    item if item["subject"].include?(subject)
  }
end