Module: DSIEmailHelper
- Defined in:
- lib/dsiemailhelper.rb,
lib/dsiemailhelper/version.rb
Constant Summary collapse
- HTTPS_REGEXP =
/https?:\/\/[\S]+/
- VERSION =
"0.0.3"
Class Method Summary collapse
- .connect ⇒ Object
- .filter_messages_by_time(messages, time, acceptable_offset = 0) ⇒ Object
- .find_email_by_gmail_search(search_string, start_time, acceptable_offset = 0) ⇒ Object
- .find_with_filters(*args) ⇒ Object
- .get_all_emails ⇒ Object
- .get_email_body(message) ⇒ Object
- .get_most_recent_email ⇒ Object
- .get_newest_password_reset_link(email) ⇒ Object
- .parse_link_from_body(decoded_message) ⇒ Object
Class Method Details
.connect ⇒ Object
10 11 12 13 14 15 |
# File 'lib/dsiemailhelper.rb', line 10 def self.connect # using connect! because only it will throw an exception if an error occurs # during the connection process with gmail raise "Please ensure QA_INBOX_EMAIL and QA_INBOX_PASSWORD env vars are configured" unless ENV['QA_INBOX_EMAIL'] && ENV['QA_INBOX_PASSWORD'] @inbox = Gmail.connect!(ENV['QA_INBOX_EMAIL'], ENV['QA_INBOX_PASSWORD']) end |
.filter_messages_by_time(messages, time, acceptable_offset = 0) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/dsiemailhelper.rb', line 40 def self.(, time, acceptable_offset=0) .delete_if { | | ..date.to_time.to_f <= time.to_time.round.to_f - acceptable_offset } end |
.find_email_by_gmail_search(search_string, start_time, acceptable_offset = 0) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/dsiemailhelper.rb', line 22 def self.find_email_by_gmail_search(search_string, start_time, acceptable_offset=0) = nil Timeout.timeout(120) do while .nil? = @inbox sleep 0.5 end = (@inbox.inbox.find(gm: search_string), start_time, acceptable_offset)[-1] end rescue Timeout::Error => e puts "Search string passed: #{search_string}" puts "Start time passed: #{start_time} (offset: #{acceptable_offset})." puts "Messages matching search string: #{@inbox.inbox.find(gm: search_string)}" puts "Message: #{ || @inbox.inbox.find(gm: search_string)}" raise e end |
.find_with_filters(*args) ⇒ Object
71 72 73 |
# File 'lib/dsiemailhelper.rb', line 71 def self.find_with_filters(*args) @inbox.inbox.find(*args) end |
.get_all_emails ⇒ Object
17 18 19 20 |
# File 'lib/dsiemailhelper.rb', line 17 def self.get_all_emails # returns an array of Message objects @inbox.inbox.emails end |
.get_email_body(message) ⇒ Object
47 48 49 50 |
# File 'lib/dsiemailhelper.rb', line 47 def self.get_email_body() # expects a Message object and returns the body of the email without encoding .text_part.body.decoded end |
.get_most_recent_email ⇒ Object
56 57 58 59 60 61 |
# File 'lib/dsiemailhelper.rb', line 56 def self.get_most_recent_email # Noticed the most recent email in the inbox folder always has the highest index, # so we can use the size of the array to determine what the most recent message is = get_all_emails [.length - 1] end |
.get_newest_password_reset_link(email) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/dsiemailhelper.rb', line 63 def self.get_newest_password_reset_link(email) = find_email_by_gmail_search("subject: Update Your Password to: #{email}", Date.today) body = get_email_body() # TODO: Archiving doesn't seem to be working, need to look into why .delete! parse_link_from_body(body) end |
.parse_link_from_body(decoded_message) ⇒ Object
52 53 54 |
# File 'lib/dsiemailhelper.rb', line 52 def self.parse_link_from_body() .scan(HTTPS_REGEXP) end |