class Toggl::Jobcan::Client
Jobcan
client
Constants
- JOBCAN_URLS
- XPATHS
Attributes
credentials[RW]
driver[R]
toggl[R]
Public Class Methods
new( credentials: nil, options: Selenium::WebDriver::Chrome::Options.new, toggl_worktime_config:, dryrun: false )
click to toggle source
# File lib/toggl/jobcan/client.rb, line 29 def initialize( credentials: nil, options: Selenium::WebDriver::Chrome::Options.new, toggl_worktime_config:, dryrun: false ) @credentials = credentials options.add_argument('--headless') @driver = Selenium::WebDriver.for :chrome, options: options @toggl = Toggl::Worktime::Driver.new( config: Toggl::Worktime::Config.new(path: toggl_worktime_config) ) @dryrun = dryrun end
Public Instance Methods
input_day_worktime(date, time_slots)
click to toggle source
# File lib/toggl/jobcan/client.rb, line 90 def input_day_worktime(date, time_slots) time_slots.flatten.each do |timestamp| input_stamp = toggl_time_format(date, timestamp) puts " - Input #{input_stamp}" navigate_to_attendance_modify_day(date) send_timestamp input_stamp send_notice @driver.find_element(:id, 'insert_button').submit unless @dryrun end end
login()
click to toggle source
# File lib/toggl/jobcan/client.rb, line 44 def login @driver.navigate.to JOBCAN_URLS[:login] send_credentials @driver.find_element(:xpath, XPATHS[:submit]).click raise JobcanLoginFailure if may_find_element(:xpath, XPATHS[:flash]) # attendance login @driver.navigate.to JOBCAN_URLS[:attendance_login] @driver.navigate.to JOBCAN_URLS[:attendance] end
select_support_for(name)
click to toggle source
# File lib/toggl/jobcan/client.rb, line 83 def select_support_for(name) Selenium::WebDriver::Support::Select.new( @driver.find_element(:xpath), %(//select[@name='#{name}']) ) end
send_credentials()
click to toggle source
# File lib/toggl/jobcan/client.rb, line 55 def send_credentials [ ['user_email', :email], ['user_password', :password] ].each do |id, method| element = @driver.find_element(:id, id) element.send_keys(@credentials.send(method)) end end
send_notice()
click to toggle source
# File lib/toggl/jobcan/client.rb, line 106 def send_notice notice_elem = @driver.find_element(:xpath, XPATHS[:notice]) notice_elem.clear notice_elem.send_keys('.') end
send_timestamp(timestamp)
click to toggle source
# File lib/toggl/jobcan/client.rb, line 101 def send_timestamp(timestamp) time_elem = @driver.find_element(:id, 'ter_time') time_elem.send_keys(timestamp) end
Private Instance Methods
may_find_element(*args)
click to toggle source
# File lib/toggl/jobcan/client.rb, line 114 def may_find_element(*args) @driver.find_element(*args) rescue Selenium::WebDriver::Error::NoSuchElementError nil end