holidays_from_google_calendar 0.4.3 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +0 -8
- data/.travis.yml +16 -1
- data/README.md +76 -4
- data/bin/console +2 -6
- data/holidays_from_google_calendar.gemspec +1 -1
- data/lib/holidays_from_google_calendar.rb +0 -7
- data/lib/holidays_from_google_calendar/cache.rb +1 -0
- data/lib/holidays_from_google_calendar/cache_unit.rb +4 -8
- data/lib/holidays_from_google_calendar/client.rb +3 -1
- data/lib/holidays_from_google_calendar/version.rb +1 -1
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d580e1150fd1410a754c1704caf0a2bd8961b45c4e19eb14298fd8a0fd754de1
|
4
|
+
data.tar.gz: 0d924ba7e83d1b72db38e2ac1eb210edaa941511098eafd5a7bcb661917204a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5c0261d1d967e2178e52de58b8b3031eb5d8a7740b9044e9136ce0b21b20d46d244244d96b75a5ccc330b6cce8999ead598547afd9420bd4a64b00002440e57
|
7
|
+
data.tar.gz: bcdf1eafebd441cb953430e2d286a42b411a213aef1f4035188869cf10eefafd8fc67b1899a2b733d07f490cb2e496a8caf64a8cd767a0702367efbcb8421f2f
|
data/.rubocop.yml
CHANGED
@@ -37,14 +37,6 @@ Style/BlockDelimiters:
|
|
37
37
|
FormatString:
|
38
38
|
EnforcedStyle: sprintf
|
39
39
|
|
40
|
-
# Maximum line length
|
41
|
-
LineLength:
|
42
|
-
Max: 100
|
43
|
-
|
44
|
-
# Whatever we should use "postfix if/unless"
|
45
|
-
IfUnlessModifier:
|
46
|
-
MaxLineLength: 100
|
47
|
-
|
48
40
|
# Maximum method length
|
49
41
|
MethodLength:
|
50
42
|
Max: 20
|
data/.travis.yml
CHANGED
@@ -1,6 +1,21 @@
|
|
1
|
+
env:
|
2
|
+
global:
|
3
|
+
- CC_TEST_REPORTER_ID=a5c4305696a06c12d5071d9c5bbda7d604be0495ad47c6199389f633fcbdaf86
|
1
4
|
language: ruby
|
2
5
|
rvm:
|
3
6
|
- 2.0
|
4
7
|
- 2.1
|
5
8
|
- 2.2
|
6
|
-
|
9
|
+
- 2.3
|
10
|
+
- 2.4
|
11
|
+
- 2.5
|
12
|
+
before_install:
|
13
|
+
- gem update --system --no-document
|
14
|
+
before_script:
|
15
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
16
|
+
- chmod +x ./cc-test-reporter
|
17
|
+
- ./cc-test-reporter before-build
|
18
|
+
after_script:
|
19
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
20
|
+
notifications:
|
21
|
+
email: false
|
data/README.md
CHANGED
@@ -1,5 +1,30 @@
|
|
1
|
-
# HolidaysFromGoogleCalendar
|
2
|
-
|
1
|
+
# HolidaysFromGoogleCalendar
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/necojackarc/holidays_from_google_calendar.svg?branch=master)](https://travis-ci.org/necojackarc/holidays_from_google_calendar)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/necojackarc/holidays_from_google_calendar/badges/gpa.svg)](https://codeclimate.com/github/necojackarc/holidays_from_google_calendar)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/necojackarc/holidays_from_google_calendar/badges/coverage.svg)](https://codeclimate.com/github/necojackarc/holidays_from_google_calendar/coverage)
|
6
|
+
|
7
|
+
HolidaysFromGoogleCalendar can retrieve national holidays from Google Calendar with very simple interface.
|
8
|
+
|
9
|
+
The results is going to be cached and you can preload holidays with your favorite range at initialization if you want.
|
10
|
+
These features help you to reduce access times to Google Calendar API.
|
11
|
+
|
12
|
+
I am sure that you only need to access the API a very few times if you preload holidays with proper range.
|
13
|
+
|
14
|
+
Using Google Calendar, available nations are same as Google Calendar.
|
15
|
+
|
16
|
+
Note that you can only retrieve holidays which Google Calendar has.
|
17
|
+
Google Calendar appears not to have all holidays, so you cannot retrieve very old ones and far future's.
|
18
|
+
|
19
|
+
## Features
|
20
|
+
### Main
|
21
|
+
* List holidays of a particular nation in a particular year
|
22
|
+
* List holidays of a particular nation in a particular month
|
23
|
+
* Check a date whether it is a holiday or not in a particular nation
|
24
|
+
|
25
|
+
### Others
|
26
|
+
* Cacheing results using LRU algorithm
|
27
|
+
* Preload holidays at initialization
|
3
28
|
|
4
29
|
## Installation
|
5
30
|
Add this line to your application's Gemfile:
|
@@ -21,7 +46,54 @@ $ gem install holidays_from_google_calendar
|
|
21
46
|
```
|
22
47
|
|
23
48
|
## Usage
|
49
|
+
### Configuration
|
50
|
+
All parameters you can pass are below:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
usa_holidays = HolidaysFromGoogleCalendar::Holidays.new do |config|
|
54
|
+
config.credential = {
|
55
|
+
api_key: "YOUR OWN GOOGLE API KEY"
|
56
|
+
}
|
57
|
+
|
58
|
+
config.calendar = {
|
59
|
+
nation: "usa",
|
60
|
+
language: "en"
|
61
|
+
}
|
24
62
|
|
63
|
+
config.cache = {
|
64
|
+
enable: true,
|
65
|
+
max_size: 1000 # DEFAULT_CACHE_SIZE is 1000
|
66
|
+
}
|
67
|
+
|
68
|
+
config.preload = {
|
69
|
+
enable: true, # Require cache enabled
|
70
|
+
date_range: 1.year # Retrive holidays from "this day last year" to "this day next year"
|
71
|
+
}
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
Default parameters of `cache` and `preload` are same as above.
|
76
|
+
|
77
|
+
### List holidays of a particular nation in a particular year
|
78
|
+
Returns a array of holidays in a particular year.
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
usa_holidays.in_year(Date.current)
|
82
|
+
```
|
83
|
+
|
84
|
+
### List holidays of a particular nation in a particular month
|
85
|
+
Returns a array of holidays in a particular month.
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
usa_holidays.in_month(Date.current)
|
89
|
+
```
|
90
|
+
|
91
|
+
### Check a date whether it is a holiday or not in a particular nation
|
92
|
+
Returns `true` when the day is holiday, Saturday or Sunday.
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
usa_holidays.holiday?(Date.current)
|
96
|
+
```
|
25
97
|
|
26
98
|
### Sample code
|
27
99
|
```ruby
|
@@ -69,7 +141,7 @@ usa_holidays.in_month(Date.parse("3rd March 2016")) # Retrieve holidays of March
|
|
69
141
|
usa_holidays.holiday?(Date.parse("Oct 31 2016")) # Halloween
|
70
142
|
=> true
|
71
143
|
|
72
|
-
usa_holidays.holiday?(Date.parse("April 16th 2016")) #
|
144
|
+
usa_holidays.holiday?(Date.parse("April 16th 2016")) # Saturday
|
73
145
|
=> true
|
74
146
|
|
75
147
|
usa_holidays.holiday?(Date.parse("April 17th 2016")) # Sunday
|
@@ -80,7 +152,7 @@ usa_holidays.holiday?(Date.parse("Aug 2 2016")) # Weekday (Tuesday)
|
|
80
152
|
```
|
81
153
|
|
82
154
|
## Development
|
83
|
-
Need to set the following environment variable to run rspec
|
155
|
+
Need to set the following environment variable to run rspec:
|
84
156
|
|
85
157
|
```bash
|
86
158
|
GOOGLE_API_KEY="YOUR OWN GOOGLE API KEY"
|
data/bin/console
CHANGED
@@ -6,9 +6,5 @@ require "holidays_from_google_calendar"
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|
9
|
+
require "pry"
|
10
|
+
Pry.start
|
@@ -24,8 +24,8 @@ Gem::Specification.new do |spec|
|
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.10"
|
26
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "pry"
|
27
28
|
spec.add_development_dependency "rspec"
|
28
29
|
spec.add_development_dependency "rspec-its"
|
29
30
|
spec.add_development_dependency "simplecov"
|
30
|
-
spec.add_development_dependency "codeclimate-test-reporter"
|
31
31
|
end
|
@@ -17,13 +17,6 @@ module HolidaysFromGoogleCalendar
|
|
17
17
|
@client = Client.new(@configuration)
|
18
18
|
end
|
19
19
|
|
20
|
-
def on_date(date)
|
21
|
-
@client.retrieve(
|
22
|
-
date_min: date,
|
23
|
-
date_max: date
|
24
|
-
)
|
25
|
-
end
|
26
|
-
|
27
20
|
def in_year(date)
|
28
21
|
@client.retrieve(
|
29
22
|
date_min: date.beginning_of_year,
|
@@ -21,18 +21,14 @@ module HolidaysFromGoogleCalendar
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def overlapped?(other)
|
24
|
-
(date_min <= other.date_max && other.date_min <= date_max) ||
|
25
|
-
(other.date_min <= date_max && date_min <= other.date_max)
|
24
|
+
(@date_min <= other.date_max && other.date_min <= @date_max + 1.day) ||
|
25
|
+
(other.date_min <= @date_max && @date_min <= other.date_max + 1.day)
|
26
26
|
end
|
27
27
|
|
28
28
|
def combine(other)
|
29
29
|
return unless overlapped?(other)
|
30
|
-
|
31
|
-
|
32
|
-
date_min = other.date_min # rubocop:disable Lint/UselessAssignment
|
33
|
-
elsif other.date_min <= date_max
|
34
|
-
date_max = other.date_max # rubocop:disable Lint/UselessAssignment
|
35
|
-
end
|
30
|
+
@date_min = [@date_min, other.date_min].min
|
31
|
+
@date_max = [@date_max, other.date_max].max
|
36
32
|
@holidays =
|
37
33
|
@holidays.concat(other.holidays).uniq.sort { |a, b| a.date <=> b.date }
|
38
34
|
end
|
@@ -50,9 +50,11 @@ module HolidaysFromGoogleCalendar
|
|
50
50
|
|
51
51
|
def pack_response_in_object(response, date_min, date_max)
|
52
52
|
response.items.reduce([]) do |array, item|
|
53
|
+
date = item.start.date
|
54
|
+
|
53
55
|
holiday = Holiday.new(
|
54
56
|
name: item.summary,
|
55
|
-
date: Date.parse(
|
57
|
+
date: date.is_a?(Date) ? date : Date.parse(date)
|
56
58
|
)
|
57
59
|
|
58
60
|
if date_min <= holiday.date && holiday.date <= date_max
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: holidays_from_google_calendar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- necojackarc
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-api-client
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '10.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: pry
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name: rspec
|
84
|
+
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: rspec-its
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: simplecov
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -167,8 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
167
|
- !ruby/object:Gem::Version
|
168
168
|
version: '0'
|
169
169
|
requirements: []
|
170
|
-
|
171
|
-
rubygems_version: 2.4.5.1
|
170
|
+
rubygems_version: 3.0.3
|
172
171
|
signing_key:
|
173
172
|
specification_version: 4
|
174
173
|
summary: Holidays from Google Calendar.
|