Class: AttendanceBot::Bot

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBot

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

#agentObject

Returns the value of attribute agent.



7
8
9
# File 'lib/attendance_bot/bot.rb', line 7

def agent
  @agent
end

Instance Method Details

#checkinObject



30
31
32
33
34
35
36
37
# File 'lib/attendance_bot/bot.rb', line 30

def checkin
  page = 
  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

#checkoutObject



39
40
41
42
43
44
45
46
# File 'lib/attendance_bot/bot.rb', line 39

def checkout
  page = 
  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

#loginObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/attendance_bot/bot.rb', line 15

def 
  page = agent.get(Settings.)
   = page.form(action: '/employee_session')

  office_field = .fields.find { |f| f.name == 'employee_session_form[office_account_name]' }
  email_field = .fields.find { |f| f.name == 'employee_session_form[account_name_or_email]' }
  password_field = .fields.find { |f| f.name == 'employee_session_form[password]' }

  office_field.value = Settings.office
  email_field.value = Settings.email
  password_field.value = Settings.password

  .submit
end