Class: Commenter

Inherits:
Object
  • Object
show all
Defined in:
lib/blogcomments.rb

Class Method Summary collapse

Class Method Details



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/blogcomments.rb', line 13

def self.postlink(url, keyword, comment, list)
  @url=url
  @keyword=keyword
  @comment=comment
  @list=list
  @list.each { |x|
   begin
     @singleurl=@url.unspin
     @singlekeyword=@keyword.unspin
     @singlecomment=@comment.unspin
     agent=Mechanize.new
     agent.log=Logger.new(STDOUT)
     agent.user_agent_alias = 'Windows Mozilla'
     agent.open_timeout=8
     agent.read_timeout=30
     agent.max_history=1
     page=agent.get("#{x}")
     if page.form_with("method"=>"POST")
       comment_form=page.form_with("method"=>"POST")
     else
       comment_form=page.form.first
     end
     comment_form.author="#{@singlekeyword}"
     comment_form.email=Faker::Internet.email
     comment_form.url="#{@singleurl}"
     comment_form.comment="#{@singlecomment}"
     page = agent.submit(comment_form)
     puts "Posted to #{x}"
   rescue
     puts "Error posting to #{x}"
   end
  }
end