Class: AskStack
- Inherits:
-
Object
- Object
- AskStack
- Defined in:
- lib/ask_stack.rb
Constant Summary collapse
- LOGIN_URL =
'http://stackoverflow.com/users/login'
Instance Attribute Summary collapse
-
#browser ⇒ Object
(also: #page)
Returns the value of attribute browser.
-
#config ⇒ Object
Returns the value of attribute config.
-
#sel ⇒ Object
Returns the value of attribute sel.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #complete_tags ⇒ Object
- #fill_form ⇒ Object
-
#initialize(config) ⇒ AskStack
constructor
A new instance of AskStack.
- #login ⇒ Object
- #run ⇒ Object
-
#similar_questions ⇒ Object
stackoverflow.com/search/titles?like=what%20is%20the%20best%20way%20to%20test%20in%20ruby%3F&_=1303413037898 returns html frag, see similar.txt.
- #stop ⇒ Object
- #submit ⇒ Object
Constructor Details
#initialize(config) ⇒ AskStack
Returns a new instance of AskStack.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ask_stack.rb', line 15 def initialize(config) @url = LOGIN_URL @browser = Selenium::Client::Driver.new \ :host => "localhost", :port => 4444, :browser => "*firefox", :url => @url, :timeout_in_second => 60 browser.start_new_browser_session browser.highlight_located_element=true browser.set_browser_log_level 'debug' @config = config end |
Instance Attribute Details
#browser ⇒ Object Also known as: page
Returns the value of attribute browser.
10 11 12 |
# File 'lib/ask_stack.rb', line 10 def browser @browser end |
#config ⇒ Object
Returns the value of attribute config.
10 11 12 |
# File 'lib/ask_stack.rb', line 10 def config @config end |
#sel ⇒ Object
Returns the value of attribute sel.
10 11 12 |
# File 'lib/ask_stack.rb', line 10 def sel @sel end |
#url ⇒ Object
Returns the value of attribute url.
10 11 12 |
# File 'lib/ask_stack.rb', line 10 def url @url end |
Class Method Details
.run ⇒ Object
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/ask_stack.rb', line 101 def self.run config = YAML::load(File.read("ask_stack.yml")) raw_question = STDIN.read.strip title = raw_question.split(/^\s*$/)[0] = raw_question.split(/^\s*$/)[-1] body = raw_question.split(/^\s*$/)[1..-2].join("\n") config[:question] = {title: title, body: body, tags: } so = AskStack.new config so.run end |
Instance Method Details
#complete_tags ⇒ Object
stackoverflow.com/filter/tags?callback=jQuery151044475735054025645_1303413170293&q=ruby&limit=6×tamp=1303413245025&_=1303413245028 sample resp: stackoverflow.com/filter/tags?q=ruby&limit=6×tamp=1303413245025&_=1303413245028
timestamp divide by 1000
jQuery151044475735054025645_1303413170293(“ruby|22235nruby-on-rails|36488nruby-on-rails-3|7173nrubygems|1569njruby|585nruby-on-rails-plugins|495”);[choi kaja~]$
96 97 98 |
# File 'lib/ask_stack.rb', line 96 def end |
#fill_form ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ask_stack.rb', line 43 def fill_form puts "Filling in question form" page.type "name=title", config[:question][:title] page.focus 'name=post-text' sleep 1 page.type "name=post-text", config[:question][:body] page.type_keys "name=post-text", " " sleep 1 page.type "name=tagnames", config[:question][:tags] end |
#login ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ask_stack.rb', line 59 def login browser.open url puts "Signing in" browser.run_script "openid.signin('google')" puts "Loading Google signin" browser.wait_for_page_to_load(7) if !at_google_signin? puts "Error: Not the Google signin page. Tomfoolery afoot." exit end # TODO separate this Open ID provider signin to pluggable class puts "On Google signin page. Signing into Google" page.type "Email", config['username'] page.type "Passwd", config['password'] puts "Signing in..." page.click "signIn", :wait_for => :page end |
#run ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ask_stack.rb', line 29 def run browser.window_maximize login page.click "nav-askquestion", :wait_for => :page fill_form sleep 3 submit sleep 2 puts "You question is posted at this URL" puts browser.get_location stop puts "Done" end |
#similar_questions ⇒ Object
stackoverflow.com/search/titles?like=what%20is%20the%20best%20way%20to%20test%20in%20ruby%3F&_=1303413037898 returns html frag, see similar.txt
85 86 87 |
# File 'lib/ask_stack.rb', line 85 def similar_questions end |
#stop ⇒ Object
77 78 79 80 |
# File 'lib/ask_stack.rb', line 77 def stop browser.close browser.stop end |
#submit ⇒ Object
54 55 56 57 |
# File 'lib/ask_stack.rb', line 54 def submit puts "Submitting" page.click 'id=submit-button', :wait_for => :page end |