Module: TravianBot::Application::Connection
- Included in:
- TravianBot::Application, Shell
- Defined in:
- lib/travian_bot/application/connection.rb
Instance Method Summary collapse
-
#get_credentials ⇒ Object
Load the credentials from ENV/.travian_bot.
-
#login ⇒ Object
Login in to travian page.
Instance Method Details
#get_credentials ⇒ Object
Load the credentials from ENV/.travian_bot
24 25 26 27 28 |
# File 'lib/travian_bot/application/connection.rb', line 24 def get_credentials credentials = YAML::load(File.open("#{ENV['HOME']}/.travian_bot")) [credentials['travian_bot']['url'], credentials['travian_bot']['usr'], credentials['travian_bot']['pwd']] end |
#login ⇒ Object
Login in to travian page
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/travian_bot/application/connection.rb', line 7 def login @url, user, password = get_credentials driver = Selenium::WebDriver.for :firefox driver.navigate.to(@url) # Get the form fields. name_input = driver.find_element(:name, 'name') password_input = driver.find_element(:name, 'password') = driver.find_element(:id, 's1') # Login name_input.send_keys(user) password_input.send_keys(password) .submit driver end |