Created
September 11, 2008 08:12
-
-
Save zh/10185 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rubygems" | |
require "mechanize" | |
require "singleton" | |
LOGIN = 'http://edno23.mobi/login'.freeze | |
POST = 'http://edno23.mobi/post'.freeze | |
USER = 'username'.freeze | |
PASS = 'password'.freeze | |
class Edno23 | |
include Singleton | |
def Edno23.login(user, pass) | |
@agent = WWW::Mechanize.new | |
@agent.user_agent_alias = 'iPhone' | |
page = @agent.get(LOGIN) | |
form = page.forms[0] | |
form.user = USER | |
form.pass = PASS | |
page = @agent.submit(form) | |
end | |
def Edno23.post(msg, attach = nil, debug = false) | |
return nil unless (@agent && msg) | |
page = @agent.get(POST) | |
form = page.forms[0] | |
form.action = POST | |
form.msg = msg | |
form.file_uploads.first.file_name = attach if attach | |
page = @agent.submit(form) | |
puts page.body if debug | |
return page | |
end | |
end | |
if $0 == __FILE__ | |
Edno23.login(USER,PASS) | |
Edno23.post(ARGV[0] ? ARGV[0] : "Testing...", ARGV[1], true) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment