Skip to content

Instantly share code, notes, and snippets.

@yonbergman
Created June 19, 2011 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yonbergman/1034767 to your computer and use it in GitHub Desktop.
Save yonbergman/1034767 to your computer and use it in GitHub Desktop.
How to get someone's attention without disturbing everyone
require 'net/http'
require 'digest/md5'
# USAGE: noodge.rb bob #send 'nudge' to bob
# noodge.rb alice 'hi alice' # sends 'hi alice' to alice
# noodge.rb alice 'bye alice' bob # send 'bye alice' to alice as bob
# each time you send as someone (via 3rd param or via application request) it will save your name into the config so that next time you won't need to set it.
API_KEY = "YOUR Notify.io API KEY"
NOODGE_FILE = ".noodge_user" # A config file to hold the FROM user
# The list of people in your office each person can have several name or nicknames (make sure not to have overlapping names'
# The google account email with which he signed up to Notify.io
# an icon to show up every message
PEOPLE = [{:names=>["yon","yonatan","bergman"],:email=>"yon@email.com",:icon=>"http://www.giftsproject.com/images/yonatan.jpg"},
{:names=>["bob","bobi","thebob"],:email=>"bob@gmail.com",:icon=>"http://www.giftsproject.com/images/asaf.jpg"},
{:names=>["alice","alica","ali"],:email=>"alice@gmail.com",:icon=>"http://www.giftsproject.com/images/martha.jpg"}
]
def cli_error(msg)
puts "ERROR: #{msg}"
exit
end
def find_person(to)
PEOPLE.each do |person|
person[:names].each do |name|
return person if name.to_s.downcase==to.to_s.downcase
end
end
nil
end
def find_person!(to)
p = find_person(to)
cli_error "There is no one named #{to} !!" if p.nil?
p
end
def who_are_you?
@me = nil
while @me.nil?
if ARGV.length > 2
user_name = ARGV[2]
elsif File.exists? NOODGE_FILE
user_name = File.read(NOODGE_FILE)
else
ARGV.clear
puts "Who are you?"
user_name = gets.chomp.gsub(" ","")
end
@me = find_person(user_name)
end
File.open(NOODGE_FILE,'w').write(@me[:names].first)
end
def send_message(to,msg=nil,title=nil)
msg ||= "nudge"
title ||= "#{@me[:names].first} says:"
params = {:api_key=>API_KEY,
:title=>title,
:text=>msg,
:icon=>@me[:icon],
:tags => "sticky", # Remove these lines if you don't want sticky notifications
:sticky=>true # Remove these lines if you don't want sticky notifications
}
Net::HTTP.post_form( post_url(to),params)
end
def hash(person)
Digest::MD5.hexdigest(person[:email])
end
def post_url(person)
URI.parse("http://api.notify.io/v1/notify/#{hash(person)}")
end
if ARGV.length < 1
cli_error "at least tell me who you're gonna send to"
end
to = find_person! ARGV.first
msg = nil
if ARGV.length > 1
msg = ARGV[1] unless ARGV[1].empty?
end
who_are_you?
send_message(to,msg)
puts "Sent"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment