Skip to content

Instantly share code, notes, and snippets.

@bengotow

bengotow/pong.rb

Created Aug 22, 2014
Embed
What would you like to do?
Ping back and forth between two email accounts over and over forever using Inbox
#!/usr/bin/env ruby
require 'inbox'
@inbox_careless = Inbox::API.new('xdfim6g4mbduytzjhn8ud490', '80q785tt4l6qn5g07c5ylwi6a', '<<token 1>>')
@inbox_emoink = Inbox::API.new('xdfim6g4mbduytzjhn8ud490', '80q785tt4l6qn5g07c5ylwi6a', '<<token 2>>')
emoink = @inbox_emoink.namespaces.first
careless = @inbox_careless.namespaces.first
while true do
puts "Checking..."
# Print out threads with the subject 'Daily Update'
careless.threads.where(:subject => 'Ping', :tag => 'unread').each do |thread|
body = thread.messages.first.body
if (body != '')
puts "Roundtrip time: " + (Time.now.to_i - body.to_i).to_s;
else
puts "Got Start Ping"
end
thread.mark_as_read!
draft = emoink.drafts.build(
:to => [{:name => 'Careless', :email => 'careless@foundry376.com'}],
:subject => "Ping",
:body => Time.now.to_i.to_s
)
draft.save!
draft.send!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment