Skip to content

Instantly share code, notes, and snippets.

@zh
Created July 8, 2009 14:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save zh/142866 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'mechanize'
require 'singleton'
LOGIN = 'http://zh.github.com/prowl_login.html'.freeze
POST = 'http://zh.github.com/prowl.html'.freeze
USER = 'PROWL_USER'.freeze
PASS = 'PROWL_PASSWORD'.freeze
class ProwlAPI
include Singleton
def ProwlAPI.login(user, pass)
@agent = WWW::Mechanize.new
@agent.user_agent_alias = 'Linux Mozilla'
page = @agent.get(LOGIN)
form = page.forms[0]
form.username = USER
form.password = PASS
page = @agent.submit(form)
end
def ProwlAPI.post(msg, debug = false)
return nil unless (@agent && msg)
page = @agent.get(POST)
form = page.forms[0]
form.message = msg
page = @agent.submit(form)
puts page.body if debug
return "OK"
end
end
if $0 == __FILE__
ProwlAPI.login(USER, PASS)
ProwlAPI.post(ARGV[0] ? ARGV[0] : "Testing...")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment