Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/necojackarc/holidays_from_google_calendar
Retriving national holidays from Google Calendar.
https://github.com/necojackarc/holidays_from_google_calendar
google-calendar holidays ruby
Last synced: 2 days ago
JSON representation
Retriving national holidays from Google Calendar.
- Host: GitHub
- URL: https://github.com/necojackarc/holidays_from_google_calendar
- Owner: necojackarc
- License: mit
- Created: 2016-02-06T06:48:02.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2022-09-27T11:51:48.000Z (over 2 years ago)
- Last Synced: 2024-12-07T02:18:23.637Z (21 days ago)
- Topics: google-calendar, holidays, ruby
- Language: Ruby
- Homepage: https://rubygems.org/gems/holidays_from_google_calendar
- Size: 37.1 KB
- Stars: 6
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# HolidaysFromGoogleCalendar
[![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)
[![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)
[![Code Climate](https://codeclimate.com/github/necojackarc/holidays_from_google_calendar/badges/gpa.svg)](https://codeclimate.com/github/necojackarc/holidays_from_google_calendar)HolidaysFromGoogleCalendar can retrieve national holidays from Google Calendar with very simple interface.
The results is going to be cached and you can preload holidays with your favorite range at initialization if you want.
These features help you to reduce access times to Google Calendar API.I am sure that you only need to access the API a very few times if you preload holidays with proper range.
Using Google Calendar, available nations are same as Google Calendar.
Note that you can only retrieve holidays which Google Calendar has.
Google Calendar appears not to have all holidays, so you cannot retrieve very old ones and far future's.## Features
### Main
* List holidays of a particular nation in a particular year
* List holidays of a particular nation in a particular month
* Check a date whether it is a holiday or not in a particular nation### Others
* Cacheing results using LRU algorithm
* Preload holidays at initialization## Installation
Add this line to your application's Gemfile:```ruby
gem 'holidays_from_google_calendar'
```And then execute:
```bash
$ bundle
```Or install it yourself as:
```bash
$ gem install holidays_from_google_calendar
```## Usage
### Configuration
All parameters you can pass are below:```ruby
usa_holidays = HolidaysFromGoogleCalendar::Holidays.new do |config|
config.credential = {
api_key: "YOUR OWN GOOGLE API KEY"
}config.calendar = {
nation: "usa",
language: "en"
}config.cache = {
enable: true,
max_size: 1000 # DEFAULT_CACHE_SIZE is 1000
}config.preload = {
enable: true, # Require cache enabled
date_range: 1.year # Retrive holidays from "this day last year" to "this day next year"
}
end
```Default parameters of `cache` and `preload` are same as above.
### List holidays of a particular nation in a particular year
Returns a array of holidays in a particular year.```ruby
usa_holidays.in_year(Date.current)
```### List holidays of a particular nation in a particular month
Returns a array of holidays in a particular month.```ruby
usa_holidays.in_month(Date.current)
```### Check a date whether it is a holiday or not in a particular nation
Returns `true` when the day is holiday, Saturday or Sunday.```ruby
usa_holidays.holiday?(Date.current)
```### Sample code
```ruby
require "holidays_from_google_calendar"usa_holidays = HolidaysFromGoogleCalendar::Holidays.new do |config|
config.calendar = {
nation: "usa",
language: "en"
}config.credential = {
api_key: "YOUR OWN GOOGLE API KEY"
}
endusa_holidays.in_year(Date.parse("2016-02-06")) # Retrieve 2016's holidays
=> [#,
#,
#,
#,
#,
#,
#,
#,
#,
#,
#,
#,
#,
#,
#,
#,
#,
#,
#,
#,
#,
#,usa_holidays.in_month(Date.parse("3rd March 2016")) # Retrieve holidays of March, 2016
=> [#,
#]usa_holidays.holiday?(Date.parse("Oct 31 2016")) # Halloween
=> trueusa_holidays.holiday?(Date.parse("April 16th 2016")) # Saturday
=> trueusa_holidays.holiday?(Date.parse("April 17th 2016")) # Sunday
=> trueusa_holidays.holiday?(Date.parse("Aug 2 2016")) # Weekday (Tuesday)
=> false
```## Development
Need to set the following environment variable to run rspec:```bash
GOOGLE_API_KEY="YOUR OWN GOOGLE API KEY"
```## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/holidays_from_google_calendar. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).