Module: Impostor::Phpbb3::Topic
- Defined in:
- lib/impostor/phpbb3.rb
Instance Method Summary collapse
-
#get_new_topic_form(page) ⇒ Object
Get the the new topic form on the page.
-
#get_new_topic_uri(forum, subject, message) ⇒ Object
return a uri used to fetch the new topic page based on the forum, subject, and message.
-
#get_topic_from_result(page) ⇒ Object
Get the new topic identifier from the result page.
-
#page_error_message(page, prepend = '') ⇒ Object
Extract the error from a page.
-
#set_subject_and_message(form, subject, message) ⇒ Object
Set the subject and message on the new topic form.
-
#validate_new_topic_result(page) ⇒ Object
Validate the result of posting the new topic.
Instance Method Details
#get_new_topic_form(page) ⇒ Object
Get the the new topic form on the page
139 140 141 142 143 |
# File 'lib/impostor/phpbb3.rb', line 139 def get_new_topic_form(page) form = page.forms.detect { |form| form.action =~ /#{Regexp.escape(self.config.config(:posting_page))}/ } raise Impostor::TopicError.new("unknown new topic page format") unless form form end |
#get_new_topic_uri(forum, subject, message) ⇒ Object
return a uri used to fetch the new topic page based on the forum, subject, and message
130 131 132 133 134 |
# File 'lib/impostor/phpbb3.rb', line 130 def get_new_topic_uri(forum, subject, ) uri = URI.join(self.config.app_root, self.config.config(:posting_page)) uri.query = "mode=post&f=#{forum}" uri end |
#get_topic_from_result(page) ⇒ Object
Get the new topic identifier from the result page
172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/impostor/phpbb3.rb', line 172 def get_topic_from_result(page) moderated = page.body =~ /it will need to be approved by a moderator/i raise Impostor::TopicModerated.new("new topic has been moderated") if moderated link = page.links.detect{ |l| l.text =~ /View your submitted message/i } link ||= page.links.detect{ |l| l.href =~ /viewtopic\.php/ } raise Impostor::TopicError.new("new topic did not post") unless link topic = link.uri.query.split('&').detect{|a| a =~ /^t=/} raise Impostor::TopicError.new("new topic did not post") unless topic topic = topic.split('=').last.to_i raise Impostor::TopicError.new("new topic did not post") if topic.zero? topic end |
#page_error_message(page, prepend = '') ⇒ Object
Extract the error from a page
189 190 191 192 193 194 |
# File 'lib/impostor/phpbb3.rb', line 189 def (page, prepend='') = page.search(".//p[@class='error']").last || '' = .text if .respond_to?(:text) prepend = '' if .empty? "#{prepend}#{}" end |
#set_subject_and_message(form, subject, message) ⇒ Object
Set the subject and message on the new topic form
148 149 150 151 152 153 |
# File 'lib/impostor/phpbb3.rb', line 148 def (form, subject, ) form.subject = subject form. = form["post"] = "Submit" form end |
#validate_new_topic_result(page) ⇒ Object
Validate the result of posting the new topic
158 159 160 161 162 163 164 165 166 167 |
# File 'lib/impostor/phpbb3.rb', line 158 def validate_new_topic_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 page end |