vgcal 0.4.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/gem_release.yml +32 -0
- data/.github/workflows/ruby.yml +1 -1
- data/.rubocop.yml +3 -0
- data/.ruby-version +1 -1
- data/Gemfile.lock +57 -65
- data/README.md +24 -8
- data/images/share-calendar.png +0 -0
- data/lib/vgcal/date_calculator.rb +66 -0
- data/lib/vgcal/google/authorizer.rb +8 -17
- data/lib/vgcal/handlers/describer.rb +29 -84
- data/lib/vgcal/my_calendar.rb +36 -20
- data/lib/vgcal/version.rb +1 -1
- data/template-credentials.json +12 -13
- data/vgcal.gemspec +4 -2
- metadata +25 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 938fb307ea0f83083ea0be72029d2cadbef0d21cd722572971dd930ca61b1d99
|
|
4
|
+
data.tar.gz: fe723a901abde038f4fa1101f845a6269528b1e75496c678b2ec7bfb2d0adade
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 07bf416164b26e0e58d0317b02680e21070a9f9079b750ed65190a896b593986c94683be5ebed130836704254c94e28a5975e12e1cd2f10b332eaa485d667b78
|
|
7
|
+
data.tar.gz: 3a0cf119ba474d765a84e70a15045f5da7dfc1ce5a9500550f6a7c5a991185731e9f89388b380a425e1f09820cca864ed5a6b0452d37afcb66010520c3f048db
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# https://docs.github.com/ja/actions/automating-builds-and-tests/building-and-testing-ruby#publishing-gems
|
|
2
|
+
name: Ruby Gem
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
push:
|
|
6
|
+
branches: [ main ]
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
build:
|
|
10
|
+
name: Build + Publish
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
permissions:
|
|
13
|
+
packages: write
|
|
14
|
+
contents: read
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v3
|
|
18
|
+
- uses: ruby/setup-ruby@v1
|
|
19
|
+
with:
|
|
20
|
+
ruby-version: '3.2.2' # Not needed with a .ruby-version file
|
|
21
|
+
- run: bundle install
|
|
22
|
+
|
|
23
|
+
- name: Publish to RubyGems
|
|
24
|
+
run: |
|
|
25
|
+
mkdir -p $HOME/.gem
|
|
26
|
+
touch $HOME/.gem/credentials
|
|
27
|
+
chmod 0600 $HOME/.gem/credentials
|
|
28
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
|
29
|
+
gem build *.gemspec
|
|
30
|
+
gem push *.gem
|
|
31
|
+
env:
|
|
32
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
data/.github/workflows/ruby.yml
CHANGED
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.
|
|
1
|
+
3.2.2
|
data/Gemfile.lock
CHANGED
|
@@ -1,35 +1,28 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
vgcal (0.
|
|
4
|
+
vgcal (0.5.0)
|
|
5
5
|
dotenv
|
|
6
|
-
google-
|
|
6
|
+
google-apis-calendar_v3
|
|
7
|
+
googleauth
|
|
7
8
|
thor (~> 1.1)
|
|
8
9
|
|
|
9
10
|
GEM
|
|
10
11
|
remote: https://rubygems.org/
|
|
11
12
|
specs:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
i18n (>= 1.6, < 2)
|
|
15
|
-
minitest (>= 5.1)
|
|
16
|
-
tzinfo (~> 2.0)
|
|
17
|
-
addressable (2.8.0)
|
|
18
|
-
public_suffix (>= 2.0.2, < 5.0)
|
|
13
|
+
addressable (2.8.4)
|
|
14
|
+
public_suffix (>= 2.0.2, < 6.0)
|
|
19
15
|
ast (2.4.2)
|
|
20
|
-
concurrent-ruby (1.1.10)
|
|
21
16
|
declarative (0.0.20)
|
|
22
|
-
diff-lcs (1.
|
|
17
|
+
diff-lcs (1.5.0)
|
|
23
18
|
dotenv (2.8.1)
|
|
24
|
-
faraday (2.
|
|
25
|
-
faraday-net_http (
|
|
19
|
+
faraday (2.7.10)
|
|
20
|
+
faraday-net_http (>= 2.0, < 3.1)
|
|
26
21
|
ruby2_keywords (>= 0.0.4)
|
|
27
|
-
faraday-net_http (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
google-apis-generator (~> 0.1)
|
|
32
|
-
google-apis-core (0.7.0)
|
|
22
|
+
faraday-net_http (3.0.2)
|
|
23
|
+
google-apis-calendar_v3 (0.32.0)
|
|
24
|
+
google-apis-core (>= 0.11.0, < 2.a)
|
|
25
|
+
google-apis-core (0.11.1)
|
|
33
26
|
addressable (~> 2.5, >= 2.5.1)
|
|
34
27
|
googleauth (>= 0.16.2, < 2.a)
|
|
35
28
|
httpclient (>= 2.8.1, < 3.a)
|
|
@@ -38,15 +31,7 @@ GEM
|
|
|
38
31
|
retriable (>= 2.0, < 4.a)
|
|
39
32
|
rexml
|
|
40
33
|
webrick
|
|
41
|
-
|
|
42
|
-
google-apis-core (>= 0.7, < 2.a)
|
|
43
|
-
google-apis-generator (0.9.0)
|
|
44
|
-
activesupport (>= 5.0)
|
|
45
|
-
gems (~> 1.2)
|
|
46
|
-
google-apis-core (>= 0.7, < 2.a)
|
|
47
|
-
google-apis-discovery_v1 (~> 0.5)
|
|
48
|
-
thor (>= 0.20, < 2.a)
|
|
49
|
-
googleauth (1.2.0)
|
|
34
|
+
googleauth (1.7.0)
|
|
50
35
|
faraday (>= 0.17.3, < 3.a)
|
|
51
36
|
jwt (>= 1.4, < 3.0)
|
|
52
37
|
memoist (~> 0.16)
|
|
@@ -54,76 +39,83 @@ GEM
|
|
|
54
39
|
os (>= 0.9, < 2.0)
|
|
55
40
|
signet (>= 0.16, < 2.a)
|
|
56
41
|
httpclient (2.8.3)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
jwt (2.4.1)
|
|
42
|
+
json (2.6.3)
|
|
43
|
+
jwt (2.7.1)
|
|
44
|
+
language_server-protocol (3.17.0.3)
|
|
61
45
|
memoist (0.16.2)
|
|
62
46
|
mini_mime (1.1.2)
|
|
63
|
-
minitest (5.16.2)
|
|
64
47
|
multi_json (1.15.0)
|
|
65
48
|
os (1.1.4)
|
|
66
|
-
parallel (1.
|
|
67
|
-
parser (3.
|
|
49
|
+
parallel (1.23.0)
|
|
50
|
+
parser (3.2.2.3)
|
|
68
51
|
ast (~> 2.4.1)
|
|
69
|
-
|
|
52
|
+
racc
|
|
53
|
+
public_suffix (5.0.3)
|
|
54
|
+
racc (1.7.1)
|
|
70
55
|
rainbow (3.1.1)
|
|
71
|
-
rake (13.0.
|
|
72
|
-
regexp_parser (2.
|
|
56
|
+
rake (13.0.6)
|
|
57
|
+
regexp_parser (2.8.1)
|
|
73
58
|
representable (3.2.0)
|
|
74
59
|
declarative (< 0.1.0)
|
|
75
60
|
trailblazer-option (>= 0.1.1, < 0.2.0)
|
|
76
61
|
uber (< 0.2.0)
|
|
77
62
|
retriable (3.1.2)
|
|
78
63
|
rexml (3.2.5)
|
|
79
|
-
rspec (3.
|
|
80
|
-
rspec-core (~> 3.
|
|
81
|
-
rspec-expectations (~> 3.
|
|
82
|
-
rspec-mocks (~> 3.
|
|
83
|
-
rspec-core (3.
|
|
84
|
-
rspec-support (~> 3.
|
|
85
|
-
rspec-expectations (3.
|
|
64
|
+
rspec (3.12.0)
|
|
65
|
+
rspec-core (~> 3.12.0)
|
|
66
|
+
rspec-expectations (~> 3.12.0)
|
|
67
|
+
rspec-mocks (~> 3.12.0)
|
|
68
|
+
rspec-core (3.12.2)
|
|
69
|
+
rspec-support (~> 3.12.0)
|
|
70
|
+
rspec-expectations (3.12.3)
|
|
86
71
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
87
|
-
rspec-support (~> 3.
|
|
88
|
-
rspec-mocks (3.
|
|
72
|
+
rspec-support (~> 3.12.0)
|
|
73
|
+
rspec-mocks (3.12.6)
|
|
89
74
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
90
|
-
rspec-support (~> 3.
|
|
91
|
-
rspec-support (3.
|
|
92
|
-
rubocop (1.
|
|
75
|
+
rspec-support (~> 3.12.0)
|
|
76
|
+
rspec-support (3.12.1)
|
|
77
|
+
rubocop (1.54.2)
|
|
93
78
|
json (~> 2.3)
|
|
79
|
+
language_server-protocol (>= 3.17.0)
|
|
94
80
|
parallel (~> 1.10)
|
|
95
|
-
parser (>= 3.
|
|
81
|
+
parser (>= 3.2.2.3)
|
|
96
82
|
rainbow (>= 2.2.2, < 4.0)
|
|
97
83
|
regexp_parser (>= 1.8, < 3.0)
|
|
98
84
|
rexml (>= 3.2.5, < 4.0)
|
|
99
|
-
rubocop-ast (>= 1.
|
|
85
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
|
100
86
|
ruby-progressbar (~> 1.7)
|
|
101
|
-
unicode-display_width (>=
|
|
102
|
-
rubocop-ast (1.
|
|
103
|
-
parser (>= 3.
|
|
104
|
-
rubocop-
|
|
87
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
88
|
+
rubocop-ast (1.29.0)
|
|
89
|
+
parser (>= 3.2.1.0)
|
|
90
|
+
rubocop-capybara (2.18.0)
|
|
91
|
+
rubocop (~> 1.41)
|
|
92
|
+
rubocop-factory_bot (2.23.1)
|
|
93
|
+
rubocop (~> 1.33)
|
|
94
|
+
rubocop-performance (1.18.0)
|
|
105
95
|
rubocop (>= 1.7.0, < 2.0)
|
|
106
96
|
rubocop-ast (>= 0.4.0)
|
|
107
|
-
rubocop-rspec (2.
|
|
108
|
-
rubocop (~> 1.
|
|
109
|
-
|
|
97
|
+
rubocop-rspec (2.22.0)
|
|
98
|
+
rubocop (~> 1.33)
|
|
99
|
+
rubocop-capybara (~> 2.17)
|
|
100
|
+
rubocop-factory_bot (~> 2.22)
|
|
101
|
+
ruby-progressbar (1.13.0)
|
|
110
102
|
ruby2_keywords (0.0.5)
|
|
111
103
|
signet (0.17.0)
|
|
112
104
|
addressable (~> 2.8)
|
|
113
105
|
faraday (>= 0.17.5, < 3.a)
|
|
114
106
|
jwt (>= 1.5, < 3.0)
|
|
115
107
|
multi_json (~> 1.10)
|
|
116
|
-
thor (1.2.
|
|
108
|
+
thor (1.2.2)
|
|
117
109
|
trailblazer-option (0.1.2)
|
|
118
|
-
tzinfo (2.0.5)
|
|
119
|
-
concurrent-ruby (~> 1.0)
|
|
120
110
|
uber (0.1.0)
|
|
121
|
-
unicode-display_width (2.2
|
|
122
|
-
webrick (1.
|
|
111
|
+
unicode-display_width (2.4.2)
|
|
112
|
+
webrick (1.8.1)
|
|
123
113
|
|
|
124
114
|
PLATFORMS
|
|
125
115
|
arm64-darwin-21
|
|
116
|
+
arm64-darwin-22
|
|
126
117
|
x86_64-darwin-19
|
|
118
|
+
x86_64-linux
|
|
127
119
|
|
|
128
120
|
DEPENDENCIES
|
|
129
121
|
bundler (~> 2.2)
|
|
@@ -135,4 +127,4 @@ DEPENDENCIES
|
|
|
135
127
|
vgcal!
|
|
136
128
|
|
|
137
129
|
BUNDLED WITH
|
|
138
|
-
2.
|
|
130
|
+
2.4.10
|
data/README.md
CHANGED
|
@@ -12,17 +12,33 @@ $ gem install vgcal
|
|
|
12
12
|
|
|
13
13
|
## First run
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
### Setup Google API
|
|
16
|
+
|
|
17
|
+
1. [Create Google Cloud project](https://developers.google.com/workspace/guides/create-project)
|
|
18
|
+
2. [Enable Google Calendar API](https://console.cloud.google.com/apis/library/calendar-json.googleapis.com)
|
|
19
|
+
3. [Create service account](https://developers.google.com/workspace/guides/create-credentials)
|
|
20
|
+
1. [Create a service account](https://developers.google.com/workspace/guides/create-credentials#create_a_service_account)
|
|
21
|
+
2. [Create credentials for a service account](https://developers.google.com/workspace/guides/create-credentials#create_credentials_for_a_service_account)
|
|
22
|
+
3. Please save the following information
|
|
23
|
+
1. Email address of the issued service account
|
|
24
|
+
2. credential.json issued to the service account
|
|
25
|
+
4. [Set up sharing settings for the Google calendar you want to display in vgcal](https://support.google.com/calendar/answer/37082)
|
|
26
|
+
1. Share a calendar with specific people
|
|
27
|
+
1. Add the email address issued in the service account.
|
|
28
|
+
1. 
|
|
29
|
+
|
|
30
|
+
### Setup vgcal
|
|
20
31
|
|
|
21
32
|
```shell
|
|
22
|
-
$ gem install vgcal
|
|
23
33
|
$ vgcal init
|
|
24
|
-
Fix the __FIX_ME__ in /Users/ito
|
|
25
|
-
|
|
34
|
+
Fix the __FIX_ME__ in /Users/shota-ito/.vgcal/credentials.json and /Users/shota-ito/.vgcal/.env
|
|
35
|
+
|
|
36
|
+
# Save the key issued by the service account as credentials.json
|
|
37
|
+
$ cp ~/Downloads/__SERVICE_ACCOUNT_KEY__.json ~/.vgcal/credentials.json
|
|
38
|
+
|
|
39
|
+
# Please write the email address of the calendar you would like to display in vgcal.
|
|
40
|
+
# This is not the email address of the service account.
|
|
41
|
+
$ vim ~/.vgcal/.env
|
|
26
42
|
```
|
|
27
43
|
|
|
28
44
|
## Usage
|
|
Binary file
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Vgcal
|
|
4
|
+
# DateCalculator
|
|
5
|
+
class DateCalculator
|
|
6
|
+
def self.start_date(options)
|
|
7
|
+
s_date = if options[:'current-week']
|
|
8
|
+
if Date.today.sunday?
|
|
9
|
+
Date.today.to_s
|
|
10
|
+
else
|
|
11
|
+
(Date.today - Date.today.wday).to_s
|
|
12
|
+
end
|
|
13
|
+
elsif options[:'next-week']
|
|
14
|
+
if Date.today.sunday?
|
|
15
|
+
(Date.today + 7).to_s
|
|
16
|
+
else
|
|
17
|
+
(Date.today + Date.today.wday - 1).to_s
|
|
18
|
+
end
|
|
19
|
+
elsif options[:date]
|
|
20
|
+
case options[:date][0]
|
|
21
|
+
when '+'
|
|
22
|
+
(Date.today + options[:date].delete('+').to_i).to_s
|
|
23
|
+
when '-'
|
|
24
|
+
(Date.today - options[:date].delete('-').to_i).to_s
|
|
25
|
+
else
|
|
26
|
+
(Date.today + options[:date].to_i).to_s
|
|
27
|
+
end
|
|
28
|
+
elsif options['start-date'] && options['end-date']
|
|
29
|
+
Date.parse(options['start-date'].to_s)
|
|
30
|
+
else
|
|
31
|
+
Date.today.to_s
|
|
32
|
+
end
|
|
33
|
+
"#{s_date}T00:00:00+09:00"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.end_date(options)
|
|
37
|
+
e_date = if options[:'current-week']
|
|
38
|
+
if Date.today.sunday?
|
|
39
|
+
(Date.today + 6).to_s
|
|
40
|
+
else
|
|
41
|
+
(Date.today + (6 - Date.today.wday)).to_s
|
|
42
|
+
end
|
|
43
|
+
elsif options[:'next-week']
|
|
44
|
+
if Date.today.sunday?
|
|
45
|
+
(Date.today + 13).to_s
|
|
46
|
+
else
|
|
47
|
+
(Date.today + 7 + (6 - Date.today.wday)).to_s
|
|
48
|
+
end
|
|
49
|
+
elsif options[:date]
|
|
50
|
+
case options[:date][0]
|
|
51
|
+
when '+'
|
|
52
|
+
(Date.today + options[:date].delete('+').to_i).to_s
|
|
53
|
+
when '-'
|
|
54
|
+
(Date.today - options[:date].delete('-').to_i).to_s
|
|
55
|
+
else
|
|
56
|
+
(Date.today + options[:date].to_i).to_s
|
|
57
|
+
end
|
|
58
|
+
elsif options['start-date'] && options['end-date']
|
|
59
|
+
Date.parse(options['end-date'].to_s)
|
|
60
|
+
else
|
|
61
|
+
Date.today.to_s
|
|
62
|
+
end
|
|
63
|
+
"#{e_date}T23:59:59+09:00"
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -1,35 +1,26 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'googleauth'
|
|
4
|
-
require 'googleauth/stores/file_token_store'
|
|
5
4
|
require 'google/apis/calendar_v3'
|
|
6
5
|
require 'fileutils'
|
|
7
6
|
|
|
8
7
|
module Vgcal
|
|
9
|
-
# for Google
|
|
8
|
+
# Class for authentication of Google API
|
|
10
9
|
class Authorizer
|
|
11
10
|
def initialize
|
|
12
|
-
@oob_uri = 'urn:ietf:wg:oauth:2.0:oob'
|
|
13
11
|
@credentials_path = "#{Dir.home}/.vgcal/credentials.json"
|
|
14
12
|
@token_path = "#{Dir.home}/.vgcal/token.yaml"
|
|
15
13
|
@scope = Google::Apis::CalendarV3::AUTH_CALENDAR_READONLY
|
|
16
14
|
end
|
|
17
15
|
|
|
18
16
|
def credentials
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
puts "Open the following URL in the browser and enter the resulting code after authorization:\n#{url}"
|
|
27
|
-
code = $stdin.gets
|
|
28
|
-
credentials = authorizer.get_and_store_credentials_from_code(
|
|
29
|
-
user_id: user_id, code: code, base_url: @oob_uri
|
|
30
|
-
)
|
|
31
|
-
end
|
|
32
|
-
credentials
|
|
17
|
+
credential = Google::Auth::ServiceAccountCredentials.make_creds(
|
|
18
|
+
json_key_io: File.open(@credentials_path),
|
|
19
|
+
scope: @scope
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
credential.fetch_access_token!
|
|
23
|
+
credential
|
|
33
24
|
end
|
|
34
25
|
end
|
|
35
26
|
end
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'thor'
|
|
4
4
|
require 'vgcal/my_calendar'
|
|
5
|
+
require 'vgcal/date_calculator'
|
|
5
6
|
require 'fileutils'
|
|
6
7
|
require 'json'
|
|
7
8
|
|
|
@@ -14,11 +15,11 @@ module Vgcal
|
|
|
14
15
|
def init
|
|
15
16
|
vgcal_dir = "#{Dir.home}/.vgcal"
|
|
16
17
|
cred_json = "#{vgcal_dir}/credentials.json"
|
|
17
|
-
dot_env
|
|
18
|
-
gem_root
|
|
19
|
-
FileUtils.mkdir_p(vgcal_dir, 0o755)
|
|
20
|
-
FileUtils.cp(File.join(gem_root,'template-credentials.json'), cred_json) unless File.exist?(cred_json)
|
|
21
|
-
FileUtils.cp(File.join(gem_root,'template.env'), dot_env) unless File.exist?(dot_env)
|
|
18
|
+
dot_env = "#{vgcal_dir}/.env"
|
|
19
|
+
gem_root = File.expand_path('../../../', __dir__ || '.')
|
|
20
|
+
FileUtils.mkdir_p(vgcal_dir, mode: 0o755)
|
|
21
|
+
FileUtils.cp(File.join(gem_root, 'template-credentials.json'), cred_json) unless File.exist?(cred_json)
|
|
22
|
+
FileUtils.cp(File.join(gem_root, 'template.env'), dot_env) unless File.exist?(dot_env)
|
|
22
23
|
puts "Fix the __FIX_ME__ in #{cred_json} and #{dot_env}"
|
|
23
24
|
end
|
|
24
25
|
|
|
@@ -33,14 +34,14 @@ module Vgcal
|
|
|
33
34
|
|
|
34
35
|
def show
|
|
35
36
|
Dotenv.load("#{Dir.home}/.vgcal/.env")
|
|
36
|
-
|
|
37
|
-
events =
|
|
37
|
+
my_calendar = MyCalendar.new(DateCalculator.start_date(options), DateCalculator.end_date(options))
|
|
38
|
+
events = my_calendar.events
|
|
38
39
|
|
|
39
40
|
case options[:output]
|
|
40
41
|
when 'json'
|
|
41
|
-
stdout_json(
|
|
42
|
-
|
|
43
|
-
stdout_default(
|
|
42
|
+
stdout_json(my_calendar.tasks(events), my_calendar.invited_meetings(events))
|
|
43
|
+
else
|
|
44
|
+
stdout_default(my_calendar.tasks(events), my_calendar.invited_meetings(events))
|
|
44
45
|
end
|
|
45
46
|
end
|
|
46
47
|
|
|
@@ -54,29 +55,33 @@ module Vgcal
|
|
|
54
55
|
|
|
55
56
|
def stdout_json(my_tasks, invited_meetings)
|
|
56
57
|
hash = {
|
|
57
|
-
start_date: "#{start_date}",
|
|
58
|
-
end_date:
|
|
59
|
-
tasks:
|
|
58
|
+
start_date: "#{DateCalculator.start_date(options)}",
|
|
59
|
+
end_date: "#{DateCalculator.end_date(options)}",
|
|
60
|
+
tasks: []
|
|
60
61
|
}
|
|
61
62
|
my_tasks.each do |task|
|
|
62
|
-
hash[:tasks].push
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
hash[:tasks].push(
|
|
64
|
+
{
|
|
65
|
+
title: task[0],
|
|
66
|
+
time: task[1],
|
|
67
|
+
task_type: 'my_task'
|
|
68
|
+
}
|
|
69
|
+
)
|
|
67
70
|
end
|
|
68
71
|
invited_meetings.each do |meeting|
|
|
69
|
-
hash[:tasks].push
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
hash[:tasks].push(
|
|
73
|
+
{
|
|
74
|
+
title: meeting[0],
|
|
75
|
+
time: meeting[1],
|
|
76
|
+
task_type: 'invited_meeting'
|
|
77
|
+
}
|
|
78
|
+
)
|
|
74
79
|
end
|
|
75
80
|
puts hash.to_json
|
|
76
81
|
end
|
|
77
82
|
|
|
78
83
|
def stdout_default(my_tasks, invited_meetings)
|
|
79
|
-
puts "Period: #{start_date} - #{end_date}"
|
|
84
|
+
puts "Period: #{DateCalculator.start_date(options)} - #{DateCalculator.end_date(options)}"
|
|
80
85
|
puts
|
|
81
86
|
my_task_time = 0
|
|
82
87
|
my_tasks.select do |n|
|
|
@@ -100,66 +105,6 @@ module Vgcal
|
|
|
100
105
|
puts " ・#{meeting[0]}: #{meeting[1]}h"
|
|
101
106
|
end
|
|
102
107
|
end
|
|
103
|
-
|
|
104
|
-
def start_date
|
|
105
|
-
s_date = if options[:'current-week']
|
|
106
|
-
if Date.today.sunday?
|
|
107
|
-
Date.today.to_s
|
|
108
|
-
else
|
|
109
|
-
(Date.today - Date.today.wday).to_s
|
|
110
|
-
end
|
|
111
|
-
elsif options[:'next-week']
|
|
112
|
-
if Date.today.sunday?
|
|
113
|
-
(Date.today + 7).to_s
|
|
114
|
-
else
|
|
115
|
-
(Date.today + Date.today.wday - 1).to_s
|
|
116
|
-
end
|
|
117
|
-
elsif options[:date]
|
|
118
|
-
case options[:date][0]
|
|
119
|
-
when '+'
|
|
120
|
-
(Date.today + options[:date].delete('+').to_i).to_s
|
|
121
|
-
when '-'
|
|
122
|
-
(Date.today - options[:date].delete('-').to_i).to_s
|
|
123
|
-
else
|
|
124
|
-
(Date.today + options[:date].to_i).to_s
|
|
125
|
-
end
|
|
126
|
-
elsif options['start-date'] && options['end-date']
|
|
127
|
-
Date.parse(options['start-date'].to_s)
|
|
128
|
-
else
|
|
129
|
-
Date.today.to_s
|
|
130
|
-
end
|
|
131
|
-
"#{s_date}T00:00:00+09:00"
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
def end_date
|
|
135
|
-
e_date = if options[:'current-week']
|
|
136
|
-
if Date.today.sunday?
|
|
137
|
-
(Date.today + 6).to_s
|
|
138
|
-
else
|
|
139
|
-
(Date.today + (6 - Date.today.wday)).to_s
|
|
140
|
-
end
|
|
141
|
-
elsif options[:'next-week']
|
|
142
|
-
if Date.today.sunday?
|
|
143
|
-
(Date.today + 13).to_s
|
|
144
|
-
else
|
|
145
|
-
(Date.today + 7 + (6 - Date.today.wday)).to_s
|
|
146
|
-
end
|
|
147
|
-
elsif options[:date]
|
|
148
|
-
case options[:date][0]
|
|
149
|
-
when '+'
|
|
150
|
-
(Date.today + options[:date].delete('+').to_i).to_s
|
|
151
|
-
when '-'
|
|
152
|
-
(Date.today - options[:date].delete('-').to_i).to_s
|
|
153
|
-
else
|
|
154
|
-
(Date.today + options[:date].to_i).to_s
|
|
155
|
-
end
|
|
156
|
-
elsif options['start-date'] && options['end-date']
|
|
157
|
-
Date.parse(options['end-date'].to_s)
|
|
158
|
-
else
|
|
159
|
-
Date.today.to_s
|
|
160
|
-
end
|
|
161
|
-
"#{e_date}T23:59:59+09:00"
|
|
162
|
-
end
|
|
163
108
|
end
|
|
164
109
|
end
|
|
165
110
|
end
|
data/lib/vgcal/my_calendar.rb
CHANGED
|
@@ -8,26 +8,28 @@ module Vgcal
|
|
|
8
8
|
class MyCalendar
|
|
9
9
|
def initialize(start_date, end_date)
|
|
10
10
|
@start_date = start_date
|
|
11
|
-
@end_date
|
|
11
|
+
@end_date = end_date
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def events
|
|
15
|
-
service
|
|
15
|
+
service = Google::Apis::CalendarV3::CalendarService.new
|
|
16
16
|
service.authorization = Vgcal::Authorizer.new.credentials
|
|
17
|
-
calendar_id
|
|
18
|
-
service.list_events(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
calendar_id = my_email_address
|
|
18
|
+
service.list_events(
|
|
19
|
+
calendar_id,
|
|
20
|
+
max_results: 100,
|
|
21
|
+
single_events: true,
|
|
22
|
+
order_by: 'startTime',
|
|
23
|
+
time_min: @start_date,
|
|
24
|
+
time_max: @end_date
|
|
25
|
+
)
|
|
24
26
|
end
|
|
25
27
|
|
|
26
28
|
# return: [["daily scrum", 0.25], ["SRE定例", 1.0], ["test", 2.0], ["task2", 1.0]]
|
|
27
29
|
def tasks(events)
|
|
28
30
|
tasks_hash = {}
|
|
29
31
|
events.items.each do |e|
|
|
30
|
-
if e.organizer
|
|
32
|
+
if e.organizer&.self && !e.summary.start_with?(*hide_words)
|
|
31
33
|
if all_day_event?(e.start.date)
|
|
32
34
|
tasks_hash[e.summary] = 0
|
|
33
35
|
else
|
|
@@ -48,19 +50,13 @@ module Vgcal
|
|
|
48
50
|
def invited_meetings(events)
|
|
49
51
|
tasks_hash = {}
|
|
50
52
|
events.items.each do |e|
|
|
51
|
-
next if
|
|
53
|
+
next if valid_event?(e)
|
|
52
54
|
|
|
53
55
|
# 単一のカレンダー内から自分が出席返答したイベントを探して計算
|
|
54
|
-
e.attendees
|
|
55
|
-
|
|
56
|
-
next if a.email != my_email_address || (a.email == my_email_address && a.response_status != 'accepted')
|
|
56
|
+
e.attendees&.each do |a|
|
|
57
|
+
next if valid_attendee?(a)
|
|
57
58
|
|
|
58
|
-
|
|
59
|
-
if tasks_hash[e.summary]
|
|
60
|
-
tasks_hash[e.summary] += task_time
|
|
61
|
-
else
|
|
62
|
-
tasks_hash[e.summary] = task_time
|
|
63
|
-
end
|
|
59
|
+
add_task_time(tasks_hash, e)
|
|
64
60
|
end
|
|
65
61
|
end
|
|
66
62
|
tasks_hash.sort.to_a
|
|
@@ -68,6 +64,26 @@ module Vgcal
|
|
|
68
64
|
|
|
69
65
|
private
|
|
70
66
|
|
|
67
|
+
def add_task_time(tasks_hash, event)
|
|
68
|
+
task_time = (event.end.date_time - event.start.date_time).to_f * 24
|
|
69
|
+
if tasks_hash[event.summary]
|
|
70
|
+
tasks_hash[event.summary] += task_time
|
|
71
|
+
else
|
|
72
|
+
tasks_hash[event.summary] = task_time
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def valid_event?(event)
|
|
77
|
+
event.organizer&.self || event.summary&.start_with?(*hide_words)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def valid_attendee?(attendee)
|
|
81
|
+
return true if attendee.email != my_email_address
|
|
82
|
+
return true if attendee.email == my_email_address && attendee.response_status != 'accepted'
|
|
83
|
+
|
|
84
|
+
false
|
|
85
|
+
end
|
|
86
|
+
|
|
71
87
|
def my_email_address
|
|
72
88
|
ENV.fetch('MY_EMAIL_ADDRESS')
|
|
73
89
|
end
|
data/lib/vgcal/version.rb
CHANGED
data/template-credentials.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
2
|
+
"type": "service_account",
|
|
3
|
+
"project_id": "__FIX_ME__",
|
|
4
|
+
"private_key_id": "__FIX_ME__",
|
|
5
|
+
"private_key": "__FIX_ME__",
|
|
6
|
+
"client_email": "__FIX_ME__",
|
|
7
|
+
"client_id": "__FIX_ME__",
|
|
8
|
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
|
9
|
+
"token_uri": "https://oauth2.googleapis.com/token",
|
|
10
|
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
|
11
|
+
"client_x509_cert_url": "__FIX_ME__",
|
|
12
|
+
"universe_domain": "googleapis.com"
|
|
13
|
+
}
|
data/vgcal.gemspec
CHANGED
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
|
14
14
|
spec.description = "%q{The vgcal command simplifies the display of Google Calendar events.}"
|
|
15
15
|
spec.homepage = "https://github.com/st1t/vgcal"
|
|
16
16
|
spec.license = "MIT"
|
|
17
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 3.
|
|
17
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 3.2")
|
|
18
18
|
spec.metadata['rubygems_mfa_required'] = "true"
|
|
19
19
|
|
|
20
20
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
@@ -30,7 +30,9 @@ Gem::Specification.new do |spec|
|
|
|
30
30
|
spec.add_development_dependency "rubocop"
|
|
31
31
|
spec.add_development_dependency "rubocop-performance"
|
|
32
32
|
spec.add_development_dependency "rubocop-rspec"
|
|
33
|
+
|
|
33
34
|
spec.add_runtime_dependency "thor", "~> 1.1"
|
|
34
|
-
spec.add_runtime_dependency "google-
|
|
35
|
+
spec.add_runtime_dependency "google-apis-calendar_v3"
|
|
36
|
+
spec.add_runtime_dependency "googleauth"
|
|
35
37
|
spec.add_runtime_dependency "dotenv"
|
|
36
38
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vgcal
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shota Ito
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2023-07-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -109,7 +109,21 @@ dependencies:
|
|
|
109
109
|
- !ruby/object:Gem::Version
|
|
110
110
|
version: '1.1'
|
|
111
111
|
- !ruby/object:Gem::Dependency
|
|
112
|
-
name: google-
|
|
112
|
+
name: google-apis-calendar_v3
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
type: :runtime
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ">="
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0'
|
|
125
|
+
- !ruby/object:Gem::Dependency
|
|
126
|
+
name: googleauth
|
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
|
114
128
|
requirements:
|
|
115
129
|
- - ">="
|
|
@@ -144,6 +158,7 @@ executables:
|
|
|
144
158
|
extensions: []
|
|
145
159
|
extra_rdoc_files: []
|
|
146
160
|
files:
|
|
161
|
+
- ".github/workflows/gem_release.yml"
|
|
147
162
|
- ".github/workflows/ruby.yml"
|
|
148
163
|
- ".gitignore"
|
|
149
164
|
- ".rspec"
|
|
@@ -158,7 +173,9 @@ files:
|
|
|
158
173
|
- bin/setup
|
|
159
174
|
- exe/vgcal
|
|
160
175
|
- images/google-calendar.png
|
|
176
|
+
- images/share-calendar.png
|
|
161
177
|
- lib/vgcal.rb
|
|
178
|
+
- lib/vgcal/date_calculator.rb
|
|
162
179
|
- lib/vgcal/google/authorizer.rb
|
|
163
180
|
- lib/vgcal/handlers/describer.rb
|
|
164
181
|
- lib/vgcal/my_calendar.rb
|
|
@@ -171,7 +188,7 @@ licenses:
|
|
|
171
188
|
- MIT
|
|
172
189
|
metadata:
|
|
173
190
|
rubygems_mfa_required: 'true'
|
|
174
|
-
post_install_message:
|
|
191
|
+
post_install_message:
|
|
175
192
|
rdoc_options: []
|
|
176
193
|
require_paths:
|
|
177
194
|
- lib
|
|
@@ -179,15 +196,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
179
196
|
requirements:
|
|
180
197
|
- - ">="
|
|
181
198
|
- !ruby/object:Gem::Version
|
|
182
|
-
version: 3.
|
|
199
|
+
version: '3.2'
|
|
183
200
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
201
|
requirements:
|
|
185
202
|
- - ">="
|
|
186
203
|
- !ruby/object:Gem::Version
|
|
187
204
|
version: '0'
|
|
188
205
|
requirements: []
|
|
189
|
-
rubygems_version: 3.
|
|
190
|
-
signing_key:
|
|
206
|
+
rubygems_version: 3.4.10
|
|
207
|
+
signing_key:
|
|
191
208
|
specification_version: 4
|
|
192
209
|
summary: "%q{The vgcal command simplifies the display of Google Calendar events.}"
|
|
193
210
|
test_files: []
|