holidays_from_google_calendar 0.4.6 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +44 -0
- data/.rubocop.yml +1 -0
- data/README.md +75 -3
- data/Rakefile +2 -0
- data/holidays_from_google_calendar.gemspec +4 -4
- data/lib/holidays_from_google_calendar/client.rb +4 -2
- data/lib/holidays_from_google_calendar/version.rb +1 -1
- data/lib/holidays_from_google_calendar.rb +3 -0
- metadata +21 -22
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 98ffb5d178e22fa195401b11f470d050452618e08b54d777c65a61c7f07c3ead
|
4
|
+
data.tar.gz: 8b1f8f362ecc9951248fe3f3ca5111591555db63c85f1777713e836abf2df6c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92dbb171814dce93210969fe7bea8d0eafbc2cd9ec554bd7a87e706ae6f864d21a0b57edcc6aba25a8948151462a3f4c2bcd630e19ca3d1f3d72480c5f90adec
|
7
|
+
data.tar.gz: 1cb498335614a96d26d6752d1f30e38b2e694208acda0c91afc1bc1474c9cc6423b8b6478434a70deac69d3c92f17c64c037385643d9225cb231698435c905e3
|
@@ -0,0 +1,44 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
workflow_dispatch:
|
5
|
+
push:
|
6
|
+
branches:
|
7
|
+
- master
|
8
|
+
pull_request_target:
|
9
|
+
branches:
|
10
|
+
- master
|
11
|
+
|
12
|
+
permissions:
|
13
|
+
contents: read
|
14
|
+
|
15
|
+
jobs:
|
16
|
+
test:
|
17
|
+
runs-on: ubuntu-latest
|
18
|
+
strategy:
|
19
|
+
matrix:
|
20
|
+
ruby-version:
|
21
|
+
- '2.6'
|
22
|
+
- '2.7'
|
23
|
+
- '3.0'
|
24
|
+
- '3.1'
|
25
|
+
|
26
|
+
steps:
|
27
|
+
- name: Checkout
|
28
|
+
uses: actions/checkout@v3
|
29
|
+
|
30
|
+
- name: Set up Ruby
|
31
|
+
uses: ruby/setup-ruby@v1
|
32
|
+
with:
|
33
|
+
ruby-version: ${{ matrix.ruby-version }}
|
34
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
35
|
+
|
36
|
+
- name: Run tests
|
37
|
+
run: bundle exec rake
|
38
|
+
env:
|
39
|
+
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
|
40
|
+
|
41
|
+
- name: Send test coverage report to Coveralls
|
42
|
+
uses: coverallsapp/github-action@master
|
43
|
+
with:
|
44
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,30 @@
|
|
1
|
-
# HolidaysFromGoogleCalendar
|
2
|
-
|
1
|
+
# HolidaysFromGoogleCalendar
|
2
|
+
|
3
|
+
[![CI](https://github.com/necojackarc/holidays_from_google_calendar/actions/workflows/ci.yml/badge.svg)](https://github.com/necojackarc/holidays_from_google_calendar/actions/workflows/ci.yml)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/necojackarc/holidays_from_google_calendar/badge.svg?branch=master)](https://coveralls.io/github/necojackarc/holidays_from_google_calendar?branch=master)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/necojackarc/holidays_from_google_calendar/badges/gpa.svg)](https://codeclimate.com/github/necojackarc/holidays_from_google_calendar)
|
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
|
data/Rakefile
CHANGED
@@ -19,14 +19,14 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_dependency "google-api-client", "~> 0.9"
|
23
22
|
spec.add_dependency "activesupport"
|
23
|
+
spec.add_dependency "google-apis-calendar_v3"
|
24
24
|
|
25
|
-
spec.add_development_dependency "bundler"
|
26
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "bundler"
|
27
26
|
spec.add_development_dependency "pry"
|
27
|
+
spec.add_development_dependency "rake"
|
28
28
|
spec.add_development_dependency "rspec"
|
29
29
|
spec.add_development_dependency "rspec-its"
|
30
30
|
spec.add_development_dependency "simplecov"
|
31
|
-
spec.add_development_dependency "
|
31
|
+
spec.add_development_dependency "simplecov-lcov"
|
32
32
|
end
|
@@ -4,7 +4,7 @@ module HolidaysFromGoogleCalendar
|
|
4
4
|
@nation = configuration.calendar[:nation]
|
5
5
|
@language = configuration.calendar[:language]
|
6
6
|
@api_key = configuration.credential[:api_key]
|
7
|
-
@cache = Cache.new(configuration.cache)
|
7
|
+
@cache = Cache.new(**configuration.cache)
|
8
8
|
|
9
9
|
return unless configuration.preload[:enable]
|
10
10
|
preload(configuration.preload[:date_range])
|
@@ -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
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support"
|
2
4
|
require "active_support/core_ext"
|
3
5
|
require "google/apis/calendar_v3"
|
@@ -33,6 +35,7 @@ module HolidaysFromGoogleCalendar
|
|
33
35
|
|
34
36
|
def holiday?(date)
|
35
37
|
return true if date.wday.in?([0, 6]) # If Sunday or Saturday
|
38
|
+
|
36
39
|
@client.retrieve(date_min: date, date_max: date).size > 0
|
37
40
|
end
|
38
41
|
end
|
metadata
CHANGED
@@ -1,31 +1,31 @@
|
|
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: 1.0.0
|
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: 2022-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: google-apis-calendar_v3
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -42,32 +42,32 @@ dependencies:
|
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
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: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: pry
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -123,7 +123,7 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: simplecov-lcov
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
@@ -143,10 +143,10 @@ executables: []
|
|
143
143
|
extensions: []
|
144
144
|
extra_rdoc_files: []
|
145
145
|
files:
|
146
|
+
- ".github/workflows/ci.yml"
|
146
147
|
- ".gitignore"
|
147
148
|
- ".rspec"
|
148
149
|
- ".rubocop.yml"
|
149
|
-
- ".travis.yml"
|
150
150
|
- CODE_OF_CONDUCT.md
|
151
151
|
- Gemfile
|
152
152
|
- LICENSE.txt
|
@@ -181,8 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
181
|
- !ruby/object:Gem::Version
|
182
182
|
version: '0'
|
183
183
|
requirements: []
|
184
|
-
|
185
|
-
rubygems_version: 2.4.5.1
|
184
|
+
rubygems_version: 3.3.22
|
186
185
|
signing_key:
|
187
186
|
specification_version: 4
|
188
187
|
summary: Holidays from Google Calendar.
|