toggl-jobcan 0.1.1 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f483f4acaf5e1c71fc862cd0c972b96b6bcab779e5fa5337d2cb401e4281c64
4
- data.tar.gz: 9d5bb360a386624b0f804eb6033d8e70228c7531cf4a5d10a65e2e6787f2986c
3
+ metadata.gz: bc7f976d582b49b1ea773466c2444bb0c51d09839b29539d02b28408bf0164df
4
+ data.tar.gz: 3f239be20f16a6a80bc3be327bbbd76f99c95a84199849940688282942539312
5
5
  SHA512:
6
- metadata.gz: 980d306d2ce43065280b5e330a63002832845ad019f6c45c9d549983ad51397861aa124c696c01436b933843f423376943bb610a63c2dc6f9b654a3a8d6d9015
7
- data.tar.gz: f944e61ca101b3d2e345aa56f4822e4311ffdd0e08cb138ab577662673d2aae764536e62e6511b8c4af5510ba0dc4e82ae9fd5e7cb4657ab2a19bd08ea03b12a
6
+ metadata.gz: 4defb674b172701021eb34f4ffd160cd5331e377c9f2dd36d016669683c9c19f99d8a811ef29319460620fad4e6eec155ddbce85348aa6e4d99d468a2c91a028
7
+ data.tar.gz: 16d153a0ae696712340305966a21b8f36b13ffba7db0d0c39cfe8ddd13fcca09570a60a2bf9e43bca14213a16578e20c6144f388dbdb592112ac512fd49e4de6
data/.rubocop.yml CHANGED
@@ -1,2 +1,21 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.5
3
+
4
+ Metrics/AbcSize:
5
+ Max: 20
6
+
7
+ Metrics/BlockLength:
8
+ Exclude:
9
+ - spec/**/*.rb
10
+
11
+ Style/EvalWithLocation:
12
+ Exclude:
13
+ - spec/**/*.rb
14
+
15
+ Style/AccessModifierDeclarations:
16
+ Exclude:
17
+ - spec/**/*.rb
18
+
19
+ Security/Eval:
20
+ Exclude:
21
+ - spec/**/*.rb
data/CHANGELOG.md ADDED
@@ -0,0 +1,55 @@
1
+ # Changelog
2
+
3
+ ## [0.4.1](https://github.com/limitusus/toggl-jobcan/tree/0.4.1) (2021-07-01)
4
+
5
+ [Full Changelog](https://github.com/limitusus/toggl-jobcan/compare/v0.4.0...0.4.1)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Newer version of toggl-worktime is required for new Toggl API endpoint [\#14](https://github.com/limitusus/toggl-jobcan/pull/14) ([limitusus](https://github.com/limitusus))
10
+ - Update rake requirement from ~\> 10.0 to ~\> 13.0 [\#12](https://github.com/limitusus/toggl-jobcan/pull/12) ([dependabot[bot]](https://github.com/apps/dependabot))
11
+ - Bump nokogiri from 1.10.3 to 1.10.8 [\#10](https://github.com/limitusus/toggl-jobcan/pull/10) ([dependabot[bot]](https://github.com/apps/dependabot))
12
+
13
+ ## [v0.4.0](https://github.com/limitusus/toggl-jobcan/tree/v0.4.0) (2019-05-22)
14
+
15
+ [Full Changelog](https://github.com/limitusus/toggl-jobcan/compare/v0.3.1...v0.4.0)
16
+
17
+ **Merged pull requests:**
18
+
19
+ - webdrivers [\#8](https://github.com/limitusus/toggl-jobcan/pull/8) ([limitusus](https://github.com/limitusus))
20
+ - Use main as a default action [\#7](https://github.com/limitusus/toggl-jobcan/pull/7) ([limitusus](https://github.com/limitusus))
21
+ - Use Thor as CLI testing preparation [\#6](https://github.com/limitusus/toggl-jobcan/pull/6) ([limitusus](https://github.com/limitusus))
22
+ - Add minimum tests [\#5](https://github.com/limitusus/toggl-jobcan/pull/5) ([limitusus](https://github.com/limitusus))
23
+
24
+ ## [v0.3.1](https://github.com/limitusus/toggl-jobcan/tree/v0.3.1) (2019-02-01)
25
+
26
+ [Full Changelog](https://github.com/limitusus/toggl-jobcan/compare/v0.3.0...v0.3.1)
27
+
28
+ **Merged pull requests:**
29
+
30
+ - Fix bug from 2019 [\#4](https://github.com/limitusus/toggl-jobcan/pull/4) ([limitusus](https://github.com/limitusus))
31
+
32
+ ## [v0.3.0](https://github.com/limitusus/toggl-jobcan/tree/v0.3.0) (2018-09-26)
33
+
34
+ [Full Changelog](https://github.com/limitusus/toggl-jobcan/compare/v0.2.0...v0.3.0)
35
+
36
+ **Merged pull requests:**
37
+
38
+ - Switch to Jobcan ID [\#3](https://github.com/limitusus/toggl-jobcan/pull/3) ([limitusus](https://github.com/limitusus))
39
+
40
+ ## [v0.2.0](https://github.com/limitusus/toggl-jobcan/tree/v0.2.0) (2018-08-01)
41
+
42
+ [Full Changelog](https://github.com/limitusus/toggl-jobcan/compare/v0.1.1...v0.2.0)
43
+
44
+ **Merged pull requests:**
45
+
46
+ - Configurable for Toggl::Worktime [\#2](https://github.com/limitusus/toggl-jobcan/pull/2) ([limitusus](https://github.com/limitusus))
47
+ - Add dryrun feature [\#1](https://github.com/limitusus/toggl-jobcan/pull/1) ([limitusus](https://github.com/limitusus))
48
+
49
+ ## [v0.1.1](https://github.com/limitusus/toggl-jobcan/tree/v0.1.1) (2018-04-02)
50
+
51
+ [Full Changelog](https://github.com/limitusus/toggl-jobcan/compare/v0.1.0...v0.1.1)
52
+
53
+
54
+
55
+ \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
data/Gemfile.lock CHANGED
@@ -1,67 +1,95 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- toggl-jobcan (0.1.0)
5
- chromedriver-helper
4
+ toggl-jobcan (0.4.1)
6
5
  selenium-webdriver
7
- toggl-worktime (>= 0.2.0)
6
+ thor
7
+ toggl-worktime (~> 0.4.0, >= 0.4.1)
8
+ webdrivers
8
9
 
9
10
  GEM
10
11
  remote: https://rubygems.org/
11
12
  specs:
12
- archive-zip (0.11.0)
13
- io-like (~> 0.3.0)
14
- awesome_print (1.8.0)
15
- byebug (10.0.2)
16
- childprocess (0.9.0)
17
- ffi (~> 1.0, >= 1.0.11)
18
- chromedriver-helper (1.2.0)
19
- archive-zip (~> 0.10)
20
- nokogiri (~> 1.8)
13
+ awesome_print (1.9.2)
14
+ byebug (11.0.1)
15
+ childprocess (3.0.0)
21
16
  coderay (1.1.2)
22
17
  diff-lcs (1.3)
23
- faraday (0.14.0)
18
+ faraday (1.4.3)
19
+ faraday-em_http (~> 1.0)
20
+ faraday-em_synchrony (~> 1.0)
21
+ faraday-excon (~> 1.1)
22
+ faraday-net_http (~> 1.0)
23
+ faraday-net_http_persistent (~> 1.1)
24
24
  multipart-post (>= 1.2, < 3)
25
- ffi (1.9.23)
26
- io-like (0.3.0)
27
- logger (1.2.8)
28
- method_source (0.9.0)
29
- mini_portile2 (2.3.0)
30
- multipart-post (2.0.0)
31
- nokogiri (1.8.2)
32
- mini_portile2 (~> 2.3.0)
33
- oj (3.5.0)
34
- pry (0.11.3)
25
+ ruby2_keywords (>= 0.0.4)
26
+ faraday-em_http (1.0.0)
27
+ faraday-em_synchrony (1.0.0)
28
+ faraday-excon (1.1.0)
29
+ faraday-net_http (1.0.1)
30
+ faraday-net_http_persistent (1.1.0)
31
+ logger (1.4.3)
32
+ method_source (0.9.2)
33
+ mini_portile2 (2.5.3)
34
+ multipart-post (2.1.1)
35
+ nokogiri (1.11.7)
36
+ mini_portile2 (~> 2.5.0)
37
+ racc (~> 1.4)
38
+ oj (3.11.7)
39
+ pastel (0.8.0)
40
+ tty-color (~> 0.5)
41
+ pry (0.12.2)
35
42
  coderay (~> 1.1.0)
36
43
  method_source (~> 0.9.0)
37
- pry-byebug (3.6.0)
38
- byebug (~> 10.0)
44
+ pry-byebug (3.7.0)
45
+ byebug (~> 11.0)
39
46
  pry (~> 0.10)
40
- rake (10.5.0)
41
- rspec (3.7.0)
42
- rspec-core (~> 3.7.0)
43
- rspec-expectations (~> 3.7.0)
44
- rspec-mocks (~> 3.7.0)
45
- rspec-core (3.7.1)
46
- rspec-support (~> 3.7.0)
47
- rspec-expectations (3.7.0)
47
+ racc (1.5.2)
48
+ rake (13.0.1)
49
+ rspec (3.8.0)
50
+ rspec-core (~> 3.8.0)
51
+ rspec-expectations (~> 3.8.0)
52
+ rspec-mocks (~> 3.8.0)
53
+ rspec-core (3.8.0)
54
+ rspec-support (~> 3.8.0)
55
+ rspec-expectations (3.8.3)
48
56
  diff-lcs (>= 1.2.0, < 2.0)
49
- rspec-support (~> 3.7.0)
50
- rspec-mocks (3.7.0)
57
+ rspec-support (~> 3.8.0)
58
+ rspec-mocks (3.8.0)
51
59
  diff-lcs (>= 1.2.0, < 2.0)
52
- rspec-support (~> 3.7.0)
53
- rspec-support (3.7.1)
54
- rubyzip (1.2.1)
55
- selenium-webdriver (3.11.0)
56
- childprocess (~> 0.5)
57
- rubyzip (~> 1.2)
58
- toggl-worktime (0.2.0)
60
+ rspec-support (~> 3.8.0)
61
+ rspec-support (3.8.0)
62
+ ruby2_keywords (0.0.4)
63
+ rubyzip (2.3.0)
64
+ selenium-webdriver (3.142.7)
65
+ childprocess (>= 0.5, < 4.0)
66
+ rubyzip (>= 1.2.2)
67
+ strings (0.2.1)
68
+ strings-ansi (~> 0.2)
69
+ unicode-display_width (>= 1.5, < 3.0)
70
+ unicode_utils (~> 1.4)
71
+ strings-ansi (0.2.0)
72
+ thor (1.1.0)
73
+ toggl-worktime (0.4.1)
59
74
  awesome_print
60
- togglv8
61
- togglv8 (1.2.1)
75
+ togglv8-limitusus
76
+ tty-table
77
+ togglv8-limitusus (1.2.1)
62
78
  faraday
63
79
  logger
64
80
  oj
81
+ tty-color (0.6.0)
82
+ tty-screen (0.8.1)
83
+ tty-table (0.12.0)
84
+ pastel (~> 0.8)
85
+ strings (~> 0.2.0)
86
+ tty-screen (~> 0.8)
87
+ unicode-display_width (2.0.0)
88
+ unicode_utils (1.4.0)
89
+ webdrivers (4.6.0)
90
+ nokogiri (~> 1.6)
91
+ rubyzip (>= 1.3.0)
92
+ selenium-webdriver (>= 3.0, < 4.0)
65
93
 
66
94
  PLATFORMS
67
95
  ruby
@@ -70,9 +98,9 @@ DEPENDENCIES
70
98
  bundler (~> 1.16)
71
99
  pry
72
100
  pry-byebug
73
- rake (~> 10.0)
101
+ rake (~> 13.0)
74
102
  rspec (~> 3.0)
75
103
  toggl-jobcan!
76
104
 
77
105
  BUNDLED WITH
78
- 1.16.1
106
+ 1.17.3
data/README.md CHANGED
@@ -1,7 +1,11 @@
1
1
  # Toggl::Jobcan
2
2
 
3
+ ![](https://img.shields.io/gem/v/toggl-jobcan.svg?style=popout)
4
+
3
5
  This gem provides `toggl-jobcan` command, which synchronises working time data in Toggl to JobCan.
4
6
 
7
+ This gem requires Ruby >= 2.5.
8
+
5
9
  ## Installation
6
10
 
7
11
  Add this line to your application's Gemfile:
@@ -12,27 +16,33 @@ gem 'toggl-jobcan'
12
16
 
13
17
  And then execute:
14
18
 
15
- $ bundle
19
+ ```console
20
+ bundle
21
+ ```
16
22
 
17
23
  Or install it yourself as:
18
24
 
19
- $ gem install toggl-jobcan
25
+ ```console
26
+ gem install toggl-jobcan
27
+ ```
20
28
 
21
29
  ## Configuration
22
30
 
23
31
  Prepare `~/.toggl` including Toggl API token so that [Toggl::Worktime](https://github.com/limitusus/toggl-worktime) works.
24
32
 
33
+ Prepare `~/.toggl_worktime` for [Toggl::Worktime](https://github.com/limitusus/toggl-worktime) (Path can be specified via `-c` option).
34
+
25
35
  Prepare `~/.jobcan` YAML file that includes:
26
36
 
37
+ From v0.3.0 you need to specify *Jobcan ID*, not *Jobcan Attendance ID*. For details read the [documentation by Jobcan](https://jobcanwf.zendesk.com/hc/ja/articles/224910508).
38
+
27
39
  ```yaml
28
- client_id: YOUR_CLIENT_ID
29
40
  email: YOUR_EMAIL_ADDRESS
30
41
  password: YOUR_PASSWORD
31
42
  ```
32
43
 
33
44
  ## Usage
34
45
 
35
-
36
46
  Pass date strings in `%Y%m%d` format.
37
47
 
38
48
  ```console
@@ -45,6 +55,8 @@ To synchronise all days in a month, utilise `seq` command:
45
55
  toggl-jobcan `seq -f '201702%02g' 1 28`
46
56
  ```
47
57
 
58
+ You can simulate the inputs with `--dryrun` option.
59
+
48
60
  ## Development
49
61
 
50
62
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -53,7 +65,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
53
65
 
54
66
  ## Contributing
55
67
 
56
- Bug reports and pull requests are welcome on GitHub at https://github.com/limitusus/toggl-jobcan. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
68
+ Bug reports and pull requests are welcome on GitHub at [limitusus/toggl-jobcan](https://github.com/limitusus/toggl-jobcan). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
57
69
 
58
70
  ## License
59
71
 
data/exe/toggl-jobcan CHANGED
@@ -4,44 +4,9 @@
4
4
  lib = File.expand_path('../lib', __dir__)
5
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
6
 
7
- require 'selenium-webdriver'
8
7
  require 'toggl/jobcan'
9
- require 'toggl/worktime'
10
8
 
11
- cred_file = "#{ENV['HOME']}/.jobcan"
9
+ # Default action: main
10
+ %w[main version help].include?(ARGV[0]) || ARGV.unshift('main')
12
11
 
13
- Version = Toggl::Jobcan::VERSION
14
-
15
- raise RangeError, 'No dates given' if ARGV.empty?
16
- target_days = ARGV.map do |s|
17
- raise RangeError, 'Invalid format' unless s.match?(/\d#{8}/)
18
- Date.parse(s)
19
- end
20
-
21
- puts 'Target days:'
22
- target_days.each do |date|
23
- puts " - #{date.strftime('%F')}"
24
- end
25
-
26
- credentials = Toggl::Jobcan::Credentials.new(path: cred_file)
27
- jobcan = Toggl::Jobcan::Client.new(credentials: credentials)
28
- jobcan.login
29
-
30
- puts 'Driver ready'
31
-
32
- target_days.each do |date|
33
- puts "Input date: #{date}"
34
- jobcan.navigate_to_attendance_modify_day(date)
35
- working_times = jobcan.fetch_toggl_worktime(date).flatten
36
- if working_times.any?(&:nil?)
37
- puts 'Includes nil data: skip'
38
- next
39
- end
40
- jobcan.input_day_worktime(date, working_times)
41
- sleep 1
42
- puts " - Finish: #{date}; Total time: #{jobcan.toggl.total_time}"
43
- end
44
-
45
- jobcan.driver.quit
46
-
47
- puts 'All Input finished'
12
+ Toggl::Jobcan::Cli.start
data/lib/toggl/jobcan.rb CHANGED
@@ -3,9 +3,11 @@
3
3
  require 'toggl/jobcan/toggl_support'
4
4
  require 'toggl/jobcan/credentials'
5
5
  require 'toggl/jobcan/client'
6
-
6
+ require 'toggl/jobcan/cli'
7
7
  require 'toggl/jobcan/version'
8
8
 
9
+ require 'toggl/worktime'
10
+
9
11
  module Toggl
10
12
  # Provides Toggl::Jobcan namespace
11
13
  module Jobcan
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+ require 'optparse'
5
+ require 'selenium-webdriver'
6
+
7
+ module Toggl
8
+ module Jobcan
9
+ # CLI provider
10
+ class Cli < Thor
11
+ package_name 'toggl-jobcan'
12
+ default_command :main
13
+
14
+ DEFAULT_JOBCAN_CREDENTIAL_FILE_PATH = "#{ENV['HOME']}/.jobcan"
15
+ DEFAULT_TOGGL_WORKTIME_CONFIG_FILE_PATH = "#{ENV['HOME']}/.toggl_worktime"
16
+
17
+ desc(
18
+ '[options] DATE [DATE...]',
19
+ 'Register worktime in Toggl into Jobcan for the given dates ' \
20
+ '("toggl-jobcan help main" for detailed usage)'
21
+ )
22
+ method_option(
23
+ :tw_config,
24
+ type: :string, aliases: '-c',
25
+ default: DEFAULT_TOGGL_WORKTIME_CONFIG_FILE_PATH,
26
+ banner: 'CONFIG', required: false,
27
+ desc: 'configuration file for toggl_worktime'
28
+ )
29
+ method_option(
30
+ :jc_credential,
31
+ type: :string, aliases: '-r',
32
+ default: DEFAULT_JOBCAN_CREDENTIAL_FILE_PATH,
33
+ banner: 'CREDENTIAL', required: false,
34
+ desc: 'credentials file for Jobcan'
35
+ )
36
+ method_option(
37
+ :days,
38
+ type: :boolean,
39
+ default: false,
40
+ desc: 'print days and exit'
41
+ )
42
+ method_option :dryrun, type: :boolean
43
+ def main(*args)
44
+ parse_args(args)
45
+ puts '*** DRYRUN MODE ***' if options[:dryrun]
46
+
47
+ show_target_days
48
+ return if options[:days]
49
+
50
+ prepare_jobcan
51
+
52
+ puts 'Driver ready'
53
+ register_days
54
+
55
+ jobcan.driver.quit
56
+ puts 'All Input finished'
57
+ end
58
+
59
+ map %w[--version -v] => :version
60
+ desc 'version', 'Show version.'
61
+ def version
62
+ puts "Version #{Toggl::Jobcan::VERSION}"
63
+ end
64
+
65
+ no_commands do # rubocop:disable Metrics/BlockLength
66
+ def initialize(*args)
67
+ super
68
+ @target_days = []
69
+ end
70
+
71
+ def parse_args(args)
72
+ @target_days = args.map do |s|
73
+ raise RangeError, "Invalid format #{s}" unless s.match?(/\d{8}/)
74
+
75
+ Date.parse(s)
76
+ end
77
+ raise NoDayGivenError if @target_days.size.zero?
78
+ end
79
+
80
+ def prepare_jobcan
81
+ @jc_credentials = Toggl::Jobcan::Credentials.new(
82
+ path: options[:jc_credential]
83
+ )
84
+ jobcan.login
85
+ end
86
+
87
+ def jobcan
88
+ @jobcan ||= Toggl::Jobcan::Client.new(
89
+ credentials: @jc_credentials,
90
+ toggl_worktime_config: options[:tw_config],
91
+ dryrun: options[:dryrun]
92
+ )
93
+ @jobcan
94
+ end
95
+
96
+ def show_target_days
97
+ puts 'Target days:'
98
+ @target_days.each do |date|
99
+ puts " - #{date.strftime('%F')}"
100
+ end
101
+ end
102
+
103
+ def register_days
104
+ @target_days.each do |date|
105
+ register_day(date)
106
+ end
107
+ end
108
+
109
+ def register_day(date)
110
+ puts "Input date: #{date}"
111
+ working_times = jobcan.fetch_toggl_worktime(date).flatten
112
+ if working_times.any?(&:nil?)
113
+ puts 'Includes nil data: skip'
114
+ return
115
+ end
116
+ jobcan.navigate_to_attendance_modify_day(date)
117
+ jobcan.input_day_worktime(date, working_times)
118
+ sleep 1
119
+ puts " - Finish: #{date}; Total time: #{jobcan.toggl.total_time}"
120
+ end
121
+ end
122
+ end
123
+
124
+ class NoDayGivenError < StandardError; end
125
+ end
126
+ end
@@ -8,15 +8,13 @@ module Toggl
8
8
  attr_reader :driver
9
9
  attr_reader :toggl
10
10
 
11
- include Toggl::Jobcan::TogglSupport
11
+ class JobcanLoginFailure < StandardError; end
12
12
 
13
- DEFAULT_CONFIG = {
14
- timezone: 'Asia/Tokyo',
15
- day_begin_hour: 6,
16
- max_working_interval: 10
17
- }.freeze
13
+ include Toggl::Jobcan::TogglSupport
18
14
 
19
15
  JOBCAN_URLS = {
16
+ login: 'https://id.jobcan.jp/users/sign_in',
17
+ attendance_login: 'https://ssl.jobcan.jp/jbcoauth/login',
20
18
  attendance: 'https://ssl.jobcan.jp/employee/attendance',
21
19
  attendance_modify: 'https://ssl.jobcan.jp/employee/adit/modify/'
22
20
  }.freeze
@@ -24,36 +22,40 @@ module Toggl
24
22
  XPATHS = {
25
23
  notice: %(//textarea[@name='notice']),
26
24
  load_button: %(//input[@value='表示']),
27
- submit: %(//button[@type='submit']),
28
- password_label: %(//label[@for='password'])
25
+ submit: %(//input[@type='submit']),
26
+ flash: %(//p[@class='flash flash__alert'])
29
27
  }.freeze
30
28
 
31
- def initialize(credentials: nil,
32
- options: Selenium::WebDriver::Chrome::Options.new)
29
+ def initialize(
30
+ credentials: nil,
31
+ options: Selenium::WebDriver::Chrome::Options.new,
32
+ toggl_worktime_config:,
33
+ dryrun: false
34
+ )
33
35
  @credentials = credentials
34
- @config = DEFAULT_CONFIG
35
36
  options.add_argument('--headless')
36
37
  @driver = Selenium::WebDriver.for :chrome, options: options
37
38
  @toggl = Toggl::Worktime::Driver.new(
38
- max_working_interval: @config[:max_working_interval]
39
+ config: Toggl::Worktime::Config.new(path: toggl_worktime_config)
39
40
  )
41
+ @dryrun = dryrun
40
42
  end
41
43
 
42
44
  def login
43
- @driver.navigate.to JOBCAN_URLS[:attendance]
44
- # login if <label for="password"> exists
45
- return unless may_find_element(:xpath, XPATHS[:password_label])
45
+ @driver.navigate.to JOBCAN_URLS[:login]
46
46
  send_credentials
47
47
  @driver.find_element(:xpath, XPATHS[:submit]).click
48
- # attendance again
48
+ raise JobcanLoginFailure if may_find_element(:xpath, XPATHS[:flash])
49
+
50
+ # attendance login
51
+ @driver.navigate.to JOBCAN_URLS[:attendance_login]
49
52
  @driver.navigate.to JOBCAN_URLS[:attendance]
50
53
  end
51
54
 
52
55
  def send_credentials
53
56
  [
54
- ['client_id', :client_id],
55
- ['email', :email],
56
- ['password', :password]
57
+ ['user_email', :email],
58
+ ['user_password', :password]
57
59
  ].each do |id, method|
58
60
  element = @driver.find_element(:id, id)
59
61
  element.send_keys(@credentials.send(method))
@@ -92,7 +94,7 @@ module Toggl
92
94
  navigate_to_attendance_modify_day(date)
93
95
  send_timestamp input_stamp
94
96
  send_notice
95
- @driver.find_element(:id, 'insert_button').submit
97
+ @driver.find_element(:id, 'insert_button').submit unless @dryrun
96
98
  end
97
99
  end
98
100
 
@@ -6,14 +6,13 @@ module Toggl
6
6
  module Jobcan
7
7
  # Jobcan credentials manager
8
8
  class Credentials
9
- attr_accessor :client_id
10
9
  attr_accessor :email
11
10
  attr_accessor :password
12
11
 
13
- ATTRS = %i[client_id email password].freeze
12
+ ATTRS = %i[email password].freeze
14
13
 
15
14
  def initialize(args)
16
- attr_set(args) if args.key?(:client_id)
15
+ attr_set(args) if args.key?(:email)
17
16
  c = self.class.load_config(args[:path])
18
17
  attr_set(c)
19
18
  end
@@ -5,16 +5,14 @@ module Toggl
5
5
  # Provides support methods for Toggl
6
6
  module TogglSupport
7
7
  def fetch_toggl_worktime(date)
8
- @toggl.merge!(
9
- date.month, date.day,
10
- @config[:day_begin_hour], @config[:timezone]
11
- )
8
+ @toggl.merge!(date.year, date.month, date.day)
12
9
  @toggl.work_time
13
10
  end
14
11
 
15
12
  def toggl_time_format(date, timestamp)
16
13
  same_day = date == timestamp.to_date
17
14
  return timestamp.strftime('%H%M') if same_day
15
+
18
16
  hour = timestamp.hour + 24
19
17
  minute = timestamp.min
20
18
  format('%02d%02d', hour, minute)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Toggl
4
4
  module Jobcan
5
- VERSION = '0.1.1'
5
+ VERSION = '0.4.1'
6
6
  end
7
7
  end
data/toggl-jobcan.gemspec CHANGED
@@ -22,12 +22,13 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_dependency 'chromedriver-helper'
26
25
  spec.add_dependency 'selenium-webdriver'
27
- spec.add_dependency 'toggl-worktime', '>= 0.2.0'
26
+ spec.add_dependency 'thor'
27
+ spec.add_dependency 'toggl-worktime', '~> 0.4.0', '>= 0.4.1'
28
+ spec.add_dependency 'webdrivers'
28
29
  spec.add_development_dependency 'bundler', '~> 1.16'
29
30
  spec.add_development_dependency 'pry'
30
31
  spec.add_development_dependency 'pry-byebug'
31
- spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rake', '~> 13.0'
32
33
  spec.add_development_dependency 'rspec', '~> 3.0'
33
34
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toggl-jobcan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomoya Kabe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-02 00:00:00.000000000 Z
11
+ date: 2021-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: chromedriver-helper
14
+ name: selenium-webdriver
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: selenium-webdriver
28
+ name: thor
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -42,16 +42,36 @@ dependencies:
42
42
  name: toggl-worktime
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.4.0
45
48
  - - ">="
46
49
  - !ruby/object:Gem::Version
47
- version: 0.2.0
50
+ version: 0.4.1
48
51
  type: :runtime
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: 0.4.0
52
58
  - - ">="
53
59
  - !ruby/object:Gem::Version
54
- version: 0.2.0
60
+ version: 0.4.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: webdrivers
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
55
75
  - !ruby/object:Gem::Dependency
56
76
  name: bundler
57
77
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +120,14 @@ dependencies:
100
120
  requirements:
101
121
  - - "~>"
102
122
  - !ruby/object:Gem::Version
103
- version: '10.0'
123
+ version: '13.0'
104
124
  type: :development
105
125
  prerelease: false
106
126
  version_requirements: !ruby/object:Gem::Requirement
107
127
  requirements:
108
128
  - - "~>"
109
129
  - !ruby/object:Gem::Version
110
- version: '10.0'
130
+ version: '13.0'
111
131
  - !ruby/object:Gem::Dependency
112
132
  name: rspec
113
133
  requirement: !ruby/object:Gem::Requirement
@@ -134,6 +154,7 @@ files:
134
154
  - ".rspec"
135
155
  - ".rubocop.yml"
136
156
  - ".travis.yml"
157
+ - CHANGELOG.md
137
158
  - CODE_OF_CONDUCT.md
138
159
  - Gemfile
139
160
  - Gemfile.lock
@@ -144,6 +165,7 @@ files:
144
165
  - bin/setup
145
166
  - exe/toggl-jobcan
146
167
  - lib/toggl/jobcan.rb
168
+ - lib/toggl/jobcan/cli.rb
147
169
  - lib/toggl/jobcan/client.rb
148
170
  - lib/toggl/jobcan/credentials.rb
149
171
  - lib/toggl/jobcan/toggl_support.rb
@@ -168,8 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
190
  - !ruby/object:Gem::Version
169
191
  version: '0'
170
192
  requirements: []
171
- rubyforge_project:
172
- rubygems_version: 2.7.3
193
+ rubygems_version: 3.1.4
173
194
  signing_key:
174
195
  specification_version: 4
175
196
  summary: Sync toggl worktime to JobCan.