holidays_from_google_calendar 0.2.0 → 0.3.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/.rubocop.yml +54 -0
- data/Rakefile +1 -1
- data/lib/holidays_from_google_calendar.rb +21 -37
- data/lib/holidays_from_google_calendar/client.rb +17 -5
- data/lib/holidays_from_google_calendar/configuration.rb +8 -6
- data/lib/holidays_from_google_calendar/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ea98c95ad38a12d3c95ae95bce204eb9922fe556
|
|
4
|
+
data.tar.gz: e04b7ada90c239f80455c9db4d2b81decc2ba8da
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d73607ef9df0b677747b7adae6a13efb66f3f31a4468a5c38d48cfa7af19f72694dbcd44ab2e3fd306f7c6150d722b621871eaf82d178ed8f631935f8de75b16
|
|
7
|
+
data.tar.gz: 3db9c1c44dcf6b6f76df199c0527fc24e4099a21f11a07b41607085f469ecef86994874ff624ae1b77c2b84dd9b9c9e57d73ca577888342fe82469bc739fcbf4
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
Include:
|
|
3
|
+
- '**/Rakefile'
|
|
4
|
+
Exclude:
|
|
5
|
+
- 'bin/*'
|
|
6
|
+
- 'Gemfile'
|
|
7
|
+
|
|
8
|
+
# Accept single-line methods with no body
|
|
9
|
+
SingleLineMethods:
|
|
10
|
+
AllowIfMethodIsEmpty: true
|
|
11
|
+
|
|
12
|
+
# Top-level documentation of classes and modules are needless
|
|
13
|
+
Documentation:
|
|
14
|
+
Enabled: false
|
|
15
|
+
|
|
16
|
+
# Allow to chain of block after another block that spans multiple lines
|
|
17
|
+
MultilineBlockChain:
|
|
18
|
+
Enabled: false
|
|
19
|
+
|
|
20
|
+
# Allow `->` literal for multi line blocks
|
|
21
|
+
Lambda:
|
|
22
|
+
Enabled: false
|
|
23
|
+
|
|
24
|
+
# Both nested and compact are okay
|
|
25
|
+
ClassAndModuleChildren:
|
|
26
|
+
Enabled: false
|
|
27
|
+
|
|
28
|
+
# Specifying param names is unnecessary
|
|
29
|
+
Style/SingleLineBlockParams:
|
|
30
|
+
Enabled: false
|
|
31
|
+
|
|
32
|
+
# Prefer Kernel#sprintf
|
|
33
|
+
FormatString:
|
|
34
|
+
EnforcedStyle: sprintf
|
|
35
|
+
|
|
36
|
+
# Maximum line length
|
|
37
|
+
LineLength:
|
|
38
|
+
Max: 100
|
|
39
|
+
|
|
40
|
+
# Whatever we should use "postfix if/unless"
|
|
41
|
+
IfUnlessModifier:
|
|
42
|
+
MaxLineLength: 100
|
|
43
|
+
|
|
44
|
+
# Maximum method length
|
|
45
|
+
MethodLength:
|
|
46
|
+
Max: 20
|
|
47
|
+
|
|
48
|
+
# Tuned to MethodLength
|
|
49
|
+
Metrics/AbcSize:
|
|
50
|
+
Max: 30
|
|
51
|
+
|
|
52
|
+
# Prefer double_quotes strings unless your string literal contains escape chars
|
|
53
|
+
StringLiterals:
|
|
54
|
+
EnforcedStyle: double_quotes
|
data/Rakefile
CHANGED
|
@@ -10,46 +10,30 @@ require "active_support/core_ext"
|
|
|
10
10
|
|
|
11
11
|
module HolidaysFromGoogleCalendar
|
|
12
12
|
class Holidays
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def in_year(date)
|
|
21
|
-
response = @client.retrieve_from_google_calendar(
|
|
22
|
-
date_min: date.beginning_of_year,
|
|
23
|
-
date_max: date.end_of_year + 1.day
|
|
24
|
-
)
|
|
25
|
-
pack_response_in_struct(response)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def in_month(date)
|
|
29
|
-
response = @client.retrieve_from_google_calendar(
|
|
30
|
-
date_min: date.beginning_of_month,
|
|
31
|
-
date_max: date.end_of_month + 1.day
|
|
32
|
-
)
|
|
33
|
-
pack_response_in_struct(response)
|
|
34
|
-
end
|
|
13
|
+
def initialize
|
|
14
|
+
@configuration = Configuration.new
|
|
15
|
+
yield @configuration
|
|
16
|
+
@client = Client.new(@configuration)
|
|
17
|
+
end
|
|
35
18
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
19
|
+
def in_year(date)
|
|
20
|
+
@client.retrieve_from_google_calendar(
|
|
21
|
+
date_min: date.beginning_of_year,
|
|
22
|
+
date_max: date.end_of_year + 1.day
|
|
23
|
+
)
|
|
24
|
+
end
|
|
41
25
|
|
|
42
|
-
|
|
26
|
+
def in_month(date)
|
|
27
|
+
@client.retrieve_from_google_calendar(
|
|
28
|
+
date_min: date.beginning_of_month,
|
|
29
|
+
date_max: date.end_of_month + 1.day
|
|
30
|
+
)
|
|
31
|
+
end
|
|
43
32
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
date: Date.parse(item.start.date)
|
|
49
|
-
)
|
|
50
|
-
array.push(holiday)
|
|
51
|
-
end
|
|
52
|
-
end
|
|
33
|
+
def holiday?(date)
|
|
34
|
+
return true if date.wday.in?([0, 6]) # If Sunday or Saturday
|
|
35
|
+
response = @client.retrieve_from_google_calendar(date_min: date, date_max: date + 1.day)
|
|
36
|
+
response.items.size > 0
|
|
53
37
|
end
|
|
54
38
|
end
|
|
55
39
|
end
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
module HolidaysFromGoogleCalendar
|
|
2
2
|
class Client
|
|
3
|
-
def initialize(
|
|
4
|
-
@nation = nation
|
|
5
|
-
@language = language
|
|
6
|
-
@api_key = api_key
|
|
3
|
+
def initialize(configuration)
|
|
4
|
+
@nation = configuration.calendar[:nation]
|
|
5
|
+
@language = configuration.calendar[:language]
|
|
6
|
+
@api_key = configuration.credential[:api_key]
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def retrieve_from_google_calendar(date_min: nil, date_max: nil)
|
|
10
10
|
service = Google::Apis::CalendarV3::CalendarService.new
|
|
11
11
|
service.key = @api_key
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
response = service.list_events(
|
|
13
14
|
calendar_id,
|
|
14
15
|
single_events: true,
|
|
15
16
|
order_by: "startTime",
|
|
16
17
|
time_min: date_to_time(date_min),
|
|
17
18
|
time_max: date_to_time(date_max)
|
|
18
19
|
)
|
|
20
|
+
pack_response_in_object(response)
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
private
|
|
@@ -27,5 +29,15 @@ module HolidaysFromGoogleCalendar
|
|
|
27
29
|
def date_to_time(date)
|
|
28
30
|
Time.parse(date.iso8601).iso8601
|
|
29
31
|
end
|
|
32
|
+
|
|
33
|
+
def pack_response_in_object(response)
|
|
34
|
+
response.items.reduce([]) do |array, item|
|
|
35
|
+
holiday = Holiday.new(
|
|
36
|
+
name: item.summary,
|
|
37
|
+
date: Date.parse(item.start.date)
|
|
38
|
+
)
|
|
39
|
+
array.push(holiday)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
30
42
|
end
|
|
31
43
|
end
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
module HolidaysFromGoogleCalendar
|
|
2
2
|
class Configuration
|
|
3
|
-
|
|
3
|
+
CALENDAR_ATTRIBUTES = %i(nation language).freeze
|
|
4
|
+
CREDENTIAL_ATTRIBUTES = %i(api_key).freeze
|
|
4
5
|
|
|
5
|
-
attr_accessor
|
|
6
|
+
attr_accessor :calendar, :credential
|
|
6
7
|
|
|
7
|
-
def
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
def initialize
|
|
9
|
+
@calendar = {
|
|
10
|
+
nation: "japanese",
|
|
11
|
+
language: "ja"
|
|
12
|
+
}
|
|
11
13
|
end
|
|
12
14
|
end
|
|
13
15
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: holidays_from_google_calendar
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- necojackarc
|
|
@@ -89,6 +89,7 @@ extra_rdoc_files: []
|
|
|
89
89
|
files:
|
|
90
90
|
- ".gitignore"
|
|
91
91
|
- ".rspec"
|
|
92
|
+
- ".rubocop.yml"
|
|
92
93
|
- ".travis.yml"
|
|
93
94
|
- CODE_OF_CONDUCT.md
|
|
94
95
|
- Gemfile
|