Module: Impostor::Phpbb2::Post
- Defined in:
- lib/impostor/phpbb2.rb
Instance Method Summary collapse
-
#get_post_form(page) ⇒ Object
return the form used for posting a message from the reply page.
-
#get_post_from_result(page) ⇒ Object
get post id from the result of posting the message form.
-
#get_reply_uri(forum, topic) ⇒ Object
return a uri used to fetch the reply page based on the forum, topic, and message.
- #page_message(page, prepend = '') ⇒ Object
-
#set_message(form, message) ⇒ Object
set the message to reply with on the reply form.
Instance Method Details
#get_post_form(page) ⇒ Object
return the form used for posting a message from the reply page
72 73 74 75 76 |
# File 'lib/impostor/phpbb2.rb', line 72 def get_post_form(page) form = page.forms.detect { |form| form.action =~ /#{Regexp.escape(self.config.config(:posting_page))}/ } raise Impostor::PostError.new("unknown reply page format#{(page, ', ')}") unless form form end |
#get_post_from_result(page) ⇒ Object
get post id from the result of posting the message form
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/impostor/phpbb2.rb', line 90 def get_post_from_result(page) = (page) if =~ /Your message has been entered successfully./ kv = page.links.collect{ |l| l.uri }.compact. collect{ |l| l.query }.compact. collect{ |q| q.split('&')}.flatten. detect{|kv| kv =~ /^p=/ } postid = URI.unescape(kv).split('#').first.split('=').last.to_i raise Impostor::PostError.new("Message did not post.") if postid.zero? return postid end too_many = =~ /You cannot make another post so soon after your last/ if too_many raise Impostor::ThrottledError.new("too many posts in too short amount of time") else raise Impostor::PostError.new("message did not post") end end |
#get_reply_uri(forum, topic) ⇒ Object
return a uri used to fetch the reply page based on the forum, topic, and message
63 64 65 66 67 |
# File 'lib/impostor/phpbb2.rb', line 63 def get_reply_uri(forum, topic) uri = URI.join(self.config.app_root, self.config.config(:posting_page)) uri.query = "mode=reply&t=#{topic}" uri end |
#page_message(page, prepend = '') ⇒ Object
111 112 113 114 115 116 |
# File 'lib/impostor/phpbb2.rb', line 111 def (page, prepend = '') = page.search("//span[@class='gen']").last || '' = .text if .respond_to?(:text) prepend = '' if .empty? "#{prepend}#{}" end |
#set_message(form, message) ⇒ Object
set the message to reply with on the reply form
81 82 83 84 85 |
# File 'lib/impostor/phpbb2.rb', line 81 def (form, ) form. = form["post"] = "Submit" form end |