Module: Impostor::Phpbb3::Post

Defined in:
lib/impostor/phpbb3.rb

Instance Method Summary collapse

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)
  error_message = page_error_message(page)
  if error_message =~ /You cannot make another post so soon after your last/
    raise Impostor::ThrottledError.new("too many posts in too short amount of time, #{error_message}")
  elsif !error_message.empty?
    raise Impostor::PostError.new(error_message)
  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_error_message(page, prepend='')
  message = page.search(".//p[@class='error']").last || ''
  message = message.text if message.respond_to?(:text)
  prepend = '' if message.empty?
  "#{prepend}#{message}"
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 set_message(form, message)
  form.message = message
  form["post"] = "Submit"
  form
end