Class: AttendanceBot::Bot
- Inherits:
-
Object
- Object
- AttendanceBot::Bot
- Defined in:
- lib/attendance_bot/bot.rb
Instance Attribute Summary collapse
-
#agent ⇒ Object
Returns the value of attribute agent.
Instance Method Summary collapse
- #checkin ⇒ Object
- #checkout ⇒ Object
-
#initialize ⇒ Bot
constructor
A new instance of Bot.
- #login ⇒ Object
Constructor Details
#initialize ⇒ Bot
Returns a new instance of Bot.
9 10 11 12 13 |
# File 'lib/attendance_bot/bot.rb', line 9 def initialize @agent = Mechanize.new path_to_config = File.dirname(__FILE__) + '/config/config.yml' Config.load_and_set_settings(path_to_config) end |
Instance Attribute Details
#agent ⇒ Object
Returns the value of attribute agent.
7 8 9 |
# File 'lib/attendance_bot/bot.rb', line 7 def agent @agent end |
Instance Method Details
#checkin ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/attendance_bot/bot.rb', line 30 def checkin page = login clock_in_form = page.forms.first user_time = clock_in_form.fields.find { |f| f.name == 'web_time_recorder_form[user_time]' } user_time.value = Time.now.to_s clock_in_form.submit end |
#checkout ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/attendance_bot/bot.rb', line 39 def checkout page = login clock_out_form = page.forms[1] user_time = clock_out_form.fields.find { |f| f.name == 'web_time_recorder_form[user_time]' } user_time.value = Time.now.to_s clock_out_form.submit end |
#login ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/attendance_bot/bot.rb', line 15 def login page = agent.get(Settings.login_url) login_form = page.form(action: '/employee_session') office_field = login_form.fields.find { |f| f.name == 'employee_session_form[office_account_name]' } email_field = login_form.fields.find { |f| f.name == 'employee_session_form[account_name_or_email]' } password_field = login_form.fields.find { |f| f.name == 'employee_session_form[password]' } office_field.value = Settings.office email_field.value = Settings.email password_field.value = Settings.password login_form.submit end |