holidays_from_google_calendar 0.4.6 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 59d4d036317d5ad1ff9807433d1a475b4643add2
4
- data.tar.gz: 896ce2010c7329bd3efb95524a9b50f5129734f2
2
+ SHA256:
3
+ metadata.gz: 98ffb5d178e22fa195401b11f470d050452618e08b54d777c65a61c7f07c3ead
4
+ data.tar.gz: 8b1f8f362ecc9951248fe3f3ca5111591555db63c85f1777713e836abf2df6c0
5
5
  SHA512:
6
- metadata.gz: b54fe874772619a7ec877990aecd1a9d2d34002b38ad6c6299f800f51656fc849adc3ed6952ad6cc4094ae81cad8898a162cb7c7b0a74649f83e6a4c03579394
7
- data.tar.gz: 496bfa2f3fb07d89940ebd86aa1305f57c64258cd1d0e71c787e8f2354b9ff3d0ba0267e934bea5549518dd911fe82c449ee783315aed325fc37e982f0782eff
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
@@ -4,6 +4,7 @@ AllCops:
4
4
  Exclude:
5
5
  - 'bin/*'
6
6
  - 'Gemfile'
7
+ NewCops: enable
7
8
 
8
9
  # Accept single-line methods with no body
9
10
  SingleLineMethods:
data/README.md CHANGED
@@ -1,5 +1,30 @@
1
- # HolidaysFromGoogleCalendar [![Build Status](https://travis-ci.org/necojackarc/holidays_from_google_calendar.svg?branch=master)](https://travis-ci.org/necojackarc/holidays_from_google_calendar) [![Code Climate](https://codeclimate.com/github/necojackarc/holidays_from_google_calendar/badges/gpa.svg)](https://codeclimate.com/github/necojackarc/holidays_from_google_calendar) [![Test Coverage](https://codeclimate.com/github/necojackarc/holidays_from_google_calendar/badges/coverage.svg)](https://codeclimate.com/github/necojackarc/holidays_from_google_calendar/coverage)
2
- Under construction.
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")) # Satruday
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
3
5
 
@@ -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", "~> 1.10"
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 "codeclimate-test-reporter"
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(item.start.date)
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,3 @@
1
1
  module HolidaysFromGoogleCalendar
2
- VERSION = "0.4.6"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -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.6
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: 2016-02-07 00:00:00.000000000 Z
11
+ date: 2022-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: google-api-client
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0.9'
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.9'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: activesupport
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: '1.10'
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: '1.10'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
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: '10.0'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: pry
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: codeclimate-test-reporter
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
- rubyforge_project:
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.
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.0
4
- - 2.1
5
- - 2.2
6
- before_install: gem install bundler -v 1.10.6