toggl-jobcan 0.1.1 → 0.2.0

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: c00b08fdda200e0497122388bb5d2db2c99900e402bcb1f5a010159e19a590e6
4
+ data.tar.gz: 24b1c959733b880de6da0df91abcace2ff1968038869f76fc3741410211e6847
5
5
  SHA512:
6
- metadata.gz: 980d306d2ce43065280b5e330a63002832845ad019f6c45c9d549983ad51397861aa124c696c01436b933843f423376943bb610a63c2dc6f9b654a3a8d6d9015
7
- data.tar.gz: f944e61ca101b3d2e345aa56f4822e4311ffdd0e08cb138ab577662673d2aae764536e62e6511b8c4af5510ba0dc4e82ae9fd5e7cb4657ab2a19bd08ea03b12a
6
+ metadata.gz: ef121f202a902d3455b7b5e3dd30b47eef1b6a2b0548a962ef4673f13f3dc1c63933cfdc68d0eb351eb5afd36f9724258b70156044c8619ce45c83fd980e1775
7
+ data.tar.gz: 763dc53f7743d916cf1dad3b946f63689affb2f1f2955d052d53e91b9b0f9561e2a99841a90fc70d2b33fef7c3960442a37ad979a612019042e258faf9ec194c
@@ -0,0 +1,17 @@
1
+ # Change Log
2
+
3
+ ## [v0.2.0](https://github.com/limitusus/toggl-jobcan/tree/v0.2.0) (2018-08-01)
4
+ [Full Changelog](https://github.com/limitusus/toggl-jobcan/compare/v0.1.1...v0.2.0)
5
+
6
+ **Merged pull requests:**
7
+
8
+ - Configurable for Toggl::Worktime [\#2](https://github.com/limitusus/toggl-jobcan/pull/2) ([limitusus](https://github.com/limitusus))
9
+ - Add dryrun feature [\#1](https://github.com/limitusus/toggl-jobcan/pull/1) ([limitusus](https://github.com/limitusus))
10
+
11
+ ## [v0.1.1](https://github.com/limitusus/toggl-jobcan/tree/v0.1.1) (2018-04-02)
12
+ [Full Changelog](https://github.com/limitusus/toggl-jobcan/compare/v0.1.0...v0.1.1)
13
+
14
+ ## [v0.1.0](https://github.com/limitusus/toggl-jobcan/tree/v0.1.0) (2018-04-02)
15
+
16
+
17
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  This gem provides `toggl-jobcan` command, which synchronises working time data in Toggl to JobCan.
4
4
 
5
+ This gem requires Ruby >= 2.5.
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -22,6 +24,8 @@ Or install it yourself as:
22
24
 
23
25
  Prepare `~/.toggl` including Toggl API token so that [Toggl::Worktime](https://github.com/limitusus/toggl-worktime) works.
24
26
 
27
+ Prepare `~/.toggl_worktime` for [Toggl::Worktime](https://github.com/limitusus/toggl-worktime) (Path can be specified via `-c` option).
28
+
25
29
  Prepare `~/.jobcan` YAML file that includes:
26
30
 
27
31
  ```yaml
@@ -32,7 +36,6 @@ password: YOUR_PASSWORD
32
36
 
33
37
  ## Usage
34
38
 
35
-
36
39
  Pass date strings in `%Y%m%d` format.
37
40
 
38
41
  ```console
@@ -45,6 +48,8 @@ To synchronise all days in a month, utilise `seq` command:
45
48
  toggl-jobcan `seq -f '201702%02g' 1 28`
46
49
  ```
47
50
 
51
+ You can simulate the inputs with `--dryrun` option.
52
+
48
53
  ## Development
49
54
 
50
55
  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.
@@ -4,27 +4,42 @@
4
4
  lib = File.expand_path('../lib', __dir__)
5
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
6
 
7
+ require 'optparse'
8
+
7
9
  require 'selenium-webdriver'
8
10
  require 'toggl/jobcan'
9
- require 'toggl/worktime'
10
11
 
11
12
  cred_file = "#{ENV['HOME']}/.jobcan"
12
13
 
13
14
  Version = Toggl::Jobcan::VERSION
14
15
 
16
+ toggl_worktime_config = "#{ENV['HOME']}/.toggl_worktime"
17
+ dryrun = false
18
+
19
+ opt = OptionParser.new
20
+ opt.on('-c CONFIG', '--tw-config CONFIG') { |v| toggl_worktime_config = v }
21
+ opt.on('--dryrun') { |v| dryrun = v }
22
+ opt.parse!(ARGV)
23
+
15
24
  raise RangeError, 'No dates given' if ARGV.empty?
16
25
  target_days = ARGV.map do |s|
17
26
  raise RangeError, 'Invalid format' unless s.match?(/\d#{8}/)
18
27
  Date.parse(s)
19
28
  end
20
29
 
30
+ puts '*** DRYRUN MODE ***' if dryrun
31
+
21
32
  puts 'Target days:'
22
33
  target_days.each do |date|
23
34
  puts " - #{date.strftime('%F')}"
24
35
  end
25
36
 
26
37
  credentials = Toggl::Jobcan::Credentials.new(path: cred_file)
27
- jobcan = Toggl::Jobcan::Client.new(credentials: credentials)
38
+ jobcan = Toggl::Jobcan::Client.new(
39
+ credentials: credentials,
40
+ toggl_worktime_config: toggl_worktime_config,
41
+ dryrun: dryrun
42
+ )
28
43
  jobcan.login
29
44
 
30
45
  puts 'Driver ready'
@@ -3,9 +3,10 @@
3
3
  require 'toggl/jobcan/toggl_support'
4
4
  require 'toggl/jobcan/credentials'
5
5
  require 'toggl/jobcan/client'
6
-
7
6
  require 'toggl/jobcan/version'
8
7
 
8
+ require 'toggl/worktime'
9
+
9
10
  module Toggl
10
11
  # Provides Toggl::Jobcan namespace
11
12
  module Jobcan
@@ -10,12 +10,6 @@ module Toggl
10
10
 
11
11
  include Toggl::Jobcan::TogglSupport
12
12
 
13
- DEFAULT_CONFIG = {
14
- timezone: 'Asia/Tokyo',
15
- day_begin_hour: 6,
16
- max_working_interval: 10
17
- }.freeze
18
-
19
13
  JOBCAN_URLS = {
20
14
  attendance: 'https://ssl.jobcan.jp/employee/attendance',
21
15
  attendance_modify: 'https://ssl.jobcan.jp/employee/adit/modify/'
@@ -28,15 +22,19 @@ module Toggl
28
22
  password_label: %(//label[@for='password'])
29
23
  }.freeze
30
24
 
31
- def initialize(credentials: nil,
32
- options: Selenium::WebDriver::Chrome::Options.new)
25
+ def initialize(
26
+ credentials: nil,
27
+ options: Selenium::WebDriver::Chrome::Options.new,
28
+ toggl_worktime_config:,
29
+ dryrun: false
30
+ )
33
31
  @credentials = credentials
34
- @config = DEFAULT_CONFIG
35
32
  options.add_argument('--headless')
36
33
  @driver = Selenium::WebDriver.for :chrome, options: options
37
34
  @toggl = Toggl::Worktime::Driver.new(
38
- max_working_interval: @config[:max_working_interval]
35
+ config: Toggl::Worktime::Config.new(path: toggl_worktime_config)
39
36
  )
37
+ @dryrun = dryrun
40
38
  end
41
39
 
42
40
  def login
@@ -92,7 +90,7 @@ module Toggl
92
90
  navigate_to_attendance_modify_day(date)
93
91
  send_timestamp input_stamp
94
92
  send_notice
95
- @driver.find_element(:id, 'insert_button').submit
93
+ @driver.find_element(:id, 'insert_button').submit unless @dryrun
96
94
  end
97
95
  end
98
96
 
@@ -5,10 +5,7 @@ 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
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Toggl
4
4
  module Jobcan
5
- VERSION = '0.1.1'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_dependency 'chromedriver-helper'
26
26
  spec.add_dependency 'selenium-webdriver'
27
- spec.add_dependency 'toggl-worktime', '>= 0.2.0'
27
+ spec.add_dependency 'toggl-worktime', '~> 0.3.0'
28
28
  spec.add_development_dependency 'bundler', '~> 1.16'
29
29
  spec.add_development_dependency 'pry'
30
30
  spec.add_development_dependency 'pry-byebug'
metadata CHANGED
@@ -1,14 +1,14 @@
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.2.0
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: 2018-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chromedriver-helper
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: toggl-worktime
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.2.0
47
+ version: 0.3.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.2.0
54
+ version: 0.3.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -134,6 +134,7 @@ files:
134
134
  - ".rspec"
135
135
  - ".rubocop.yml"
136
136
  - ".travis.yml"
137
+ - CHANGELOG.md
137
138
  - CODE_OF_CONDUCT.md
138
139
  - Gemfile
139
140
  - Gemfile.lock