-
Notifications
You must be signed in to change notification settings - Fork 0
/
pinger.rb
53 lines (49 loc) · 1.32 KB
/
pinger.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require File.expand_path(File.dirname(__FILE__) + '/notifier')
class Pinger
def initialize(settings)
@settings = settings
@notifier = Notifier.new settings
@services = []
@settings['services'].each do |s|
@services.push(s.to_sym)
end
end
def has_any_term?(terms,text)
terms.each do |term|
return true if text.include? term
end
return false
end
def has_all_terms?(terms,text)
terms.each do |term|
return false unless text.include? term
end
end
def search_terms(terms,text,search_type=:any)
if search_type==:all
return has_all_terms?(terms,text)
else
return has_any_term?(terms,text)
end
end
def get_emails(service,sender)
case service
when :gmail then
require 'gmail'
gmail = Gmail.new(@settings["email"],@settings["password"])
gmail.peek = true
return gmail.inbox.emails(:unread, :from=>sender)
else "Implement it :)"
end
end
def start(search_type=:any)
@settings['senders'].each do |sender|
get_emails(:gmail,sender).each do |email|
if search_terms(@settings['terms'],email.body.to_s.downcase,search_type)
@notifier.notify(email.subject,@services)
email.mark(:read)
end
end
end
end
end