Module: Impostor::Phpbb2::Post

Defined in:
lib/impostor/phpbb2.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/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_message(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)
  message = page_message(page)
  if message =~ /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 = message =~ /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_message(page, prepend = '')
  message = page.search("//span[@class='gen']").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/phpbb2.rb', line 81

def set_message(form, message)
  form.message = message
  form["post"] = "Submit"
  form
end