Skip to content

Instantly share code, notes, and snippets.

@tpett
Created April 16, 2011 00:03
Show Gist options
  • Save tpett/922681 to your computer and use it in GitHub Desktop.
Save tpett/922681 to your computer and use it in GitHub Desktop.
Ruby script to send yourself Notifo notifications with the 'notifo' gem
#!/usr/bin/env ruby
##
# notifo -- A simple Ruby script to send yourself a push notification via Notifo
#
# Usage:
#
# 1. Create a Notifo account (if you don't already have one) at notifo.com
# 2. Create a ~/.notifo file in the format NOTIFO_USERNAME:API_PASSWORD
# 3. $ gem install notifo
# 4. Add this script to your path
# 5. $ notifo "Hello World"
#
# You can setup notifications to be pushed to your iPhone or Email account on Notifo's website.
#
# Enjoy!
#
##
require 'rubygems'
require 'notifo'
require 'optparse'
CONFIG_FILE = File.expand_path('~/.notifo')
msg = {}
unless File.exists?(CONFIG_FILE)
raise "Add configuration file @ ~/.notifo in the format NOTIFO_USERNAME:API_PASSWORD"
end
# Read in the config file
file = File.open(CONFIG_FILE, 'r')
(msg[:user], msg[:pass]) = file.readlines.join.strip.split(':')
file.close
# Parse command line options
parser = OptionParser.new do |opts|
opts.banner = "usage: notifo MESSAGE"
opts.separator "Send a message to yourself (#{msg[:user]}) via the notifo service"
opts.separator ""
opts.separator "Options:"
opts.on('-t TITLE', '--title TITLE', 'Use this title') { |title| msg[:title] = title }
opts.on('-u URI', '--uri URI', 'Attach this URI') { |uri| msg[:uri] = uri }
# opts.on('-l LABEL', '--label LABEL', 'Attach this label') { |lbl| msg[:label] = lbl }
opts.on('-h', '--help', 'Display this text') do
puts opts
exit
end
end
parser.parse!
# Set message text and default title
msg[:message] = ARGV[0]
msg[:title] ||= "Command Line Message"
# Only send if user provided a message otherwise print out usage and quit
if msg[:message]
notifo = Notifo.new(msg[:user], msg[:pass])
notifo.post(msg[:user], msg[:message], msg[:title], msg[:uri])#, msg[:label])
else
puts parser
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment