Class: Discuz::Robot
- Inherits:
-
Object
- Object
- Discuz::Robot
- Defined in:
- lib/discuz_robot.rb
Instance Method Summary collapse
-
#initialize(base_url = "http://localhost/bbs/") ⇒ Robot
constructor
A new instance of Robot.
- #login(username, password) ⇒ Object
- #post(forum_id, subject, message, options = {}) ⇒ Object
Constructor Details
Instance Method Details
#login(username, password) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/discuz_robot.rb', line 11 def login username, password form_url = @base_url + "logging.php?action=login" form_resp = @agent.get form_url, :save_cookie => true form_doc = Nokogiri::HTML(form_resp) formhash_input = form_doc.css("form input[name=formhash]") if formhash_input.first # Login formhash = formhash_input.first['value'] login_url = @base_url + "logging.php?action=login&loginsubmit=yes&inajax=0" @agent.post login_url, "submit=true&formhash=#{formhash}&loginfield=username&username=#{username}&password=#{password}&questionid=0&answer=&cookietime=2592000", :save_cookie => true else # Already logged in (this can happen if login is called multiple times in one session) end end |
#post(forum_id, subject, message, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/discuz_robot.rb', line 28 def post forum_id, subject, , = {} form_url = @base_url + "post.php?action=newthread&fid=#{forum_id}" form_resp = @agent.get form_url # puts form_resp form_doc = Nokogiri::HTML(form_resp) formhash = form_doc.css("form input[name=formhash]").first['value'] posttime = form_doc.css("form input[name=posttime]").first['value'] post_url = @base_url + "post.php?action=newthread&fid=#{forum_id}&extra=&topicsubmit=yes" @agent.post post_url, "action=newthread&fid=#{forum_id}&formhash=#{formhash}&posttime=#{posttime}&subject=#{subject}&message=#{}" end |