Module: Impostor::Phpbb3::Post
- Defined in:
- lib/impostor/phpbb3.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_error_message(page, prepend = '') ⇒ Object
Extract the error from a page.
-
#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/phpbb3.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") 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 110 |
# File 'lib/impostor/phpbb3.rb', line 90 def get_post_from_result(page) = (page) if =~ /You cannot make another post so soon after your last/ raise Impostor::ThrottledError.new("too many posts in too short amount of time, #{}") elsif !.empty? raise Impostor::PostError.new() end begin kv = page.links.collect{ |l| l.uri }.compact. collect{ |l| l.query }.compact. collect{ |q| q.split('&')}.flatten. detect { |p| p =~ /^p=/ } raise StandardError.new("Message did not post.") if kv.nil? postid = URI.unescape(kv).split('#').first.split('=').last.to_i raise StandardError.new("Message did not post.") if postid.zero? postid rescue StandardError => err raise Impostor::PostError.new(err) 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/phpbb3.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&f=#{forum}&t=#{topic}" uri end |
#page_error_message(page, prepend = '') ⇒ Object
Extract the error from a page
115 116 117 118 119 120 |
# File 'lib/impostor/phpbb3.rb', line 115 def (page, prepend='') = page.search(".//p[@class='error']").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/phpbb3.rb', line 81 def (form, ) form. = form["post"] = "Submit" form end |