
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
A ruby gem to generate 'Add To Calendar' URLs for Android, Apple, Google, Hey, Office 365, Outlook, Outlook.com and Yahoo calendars.
If this gem brings you some value feel free to buy me a coffee :)
Add this line to your application's Gemfile:
gem 'add_to_calendar'
And then execute:
$ bundle
Or install it yourself as:
$ gem install add_to_calendar
# create new instance, adding your event attributes
@cal = AddToCalendar::URLs.new(
start_datetime: Time.new(2020,12,12,13,30,00,0),
title: "Christmas party!",
timezone: 'Europe/London'
)
# access 'add to calendar' URLs
@cal.google_url
#=> "https://www.google.com/calendar/render?action=TEMPLATE&text=Christmas%20party%21&dates=20201212T133000/20201212T143000&ctz=Europe/London"
@cal.yahoo_url
#=> "https://calendar.yahoo.com/?v=60&view=d&type=20&title=Christmas%20party%21&st=20201212T133000Z&dur=0100"
@cal.hey_url
#=> "https://app.hey.com/calendar/ical_events/new?ical_source=BEGIN%3AVCALENDAR%0AVERSION%3A2.0%0APRODID%3A-//AddToCalendar//RubyGem//EN%0ABEGIN%3AVEVENT%0ASUMMARY%3AHolly%27s%209th%20birthday%21%0ADTSTAMP%3A20240913T151029Z%0ADTSTART%3A20240906T123000Z%0ADTEND%3A20240906T133000Z%0AUID%3A-20240906T123000Z-Holly%27s%209th%20birthday%21%0AEND%3AVEVENT%0AEND%3AVCALENDAR"
@cal.office365_url
#=> "https://outlook.office.com/calendar/0/action/compose?rru=addevent&subject=Christmas%20party%21&startdt=2020-12-12T13:30:00Z&enddt=2020-12-12T14:30:00Z"
# For outlook.com, different to Outlook the desktop application below
@cal.outlook_com_url
#=> "https://outlook.live.com/calendar/0/action/compose?rru=addevent&subject=Christmas%20party%21&startdt=2020-12-12T13:30:00Z&enddt=2020-12-12T14:30:00Z"
# ical provides a data-uri which will download a properly formatted *.ics file (see 'Creating HTML links' section)
@cal.ical_url
#=> "data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%0ABEGIN:VEVENT%0ADTSTART:20201212T133000Z%0ADTEND:20201212T143000Z%0ASUMMARY:Christmas%20party%21%0AUID:-20201212T133000Z-Christmas%20party%21%0AEND:VEVENT%0AEND:VCALENDAR"
# android_url, apple_url and outlook_url are simply helper methods that call ical_url and return the same string.
<!-- Simply pass the url into the href Eg. in ERB -->
<a href="<%= @cal.google_url %>">Add to Google Calendar</a>
<a href="<%= @cal.yahoo_url %>">Add to Yahoo Calendar</a>
<!-- for ical_url, android_url, apple_url and outlook_url you can set the filename like so -->
<a download="calendar-event.ics" href="<%= @cal.ical_url %>">Download iCal</a>
event_attributes = {
start_datetime: Time.new(2020,12,12,9,00,00,0), # required
end_datetime: Time.new(2020,12,12,17,00,00,0),
title: "Ruby Conference", # required
timezone: 'America/New_York', # required
location: "20 W 34th St, New York, NY 10001",
url: "https://www.ruby-lang.org/en/",
description: "Join us to learn all about Ruby.",
add_url_to_description: true, # defaults to true
all_day: true, # defaults to false
organizer: {
name: "First Last",
email: "email@example.com"
}
}
cal = AddToCalendar::URLs.new(**event_attributes)
Attribute | Required? | Class | Notes |
---|---|---|---|
start_datetime | Yes | Time | |
end_datetime | No | Time |
|
title | Yes | String | |
timezone | Yes | String | Must be in tz database format Eg. 'Europe/London', 'America/New_York' |
location | No | String | |
url | No | String | Most providers do not have a native URL field. If you set url it will be added to the end of the description field (see add_url_to_description ) |
description | No | String | Accepts newlines by passing \n Eg. "Join us for fun & drinks\n\nPS. Smart casual" |
add_url_to_description | No | true/false | Defaults to true . Set add_url_to_description: false to stop the URL from being added to the description |
all_day | No | true/false |
|
organizer | No | Hash |
|
timezone
.2020-05-13 13:30:00
will save in a New Yorker's calendar as local time 2020-05-13 17:30:00
ical_url
, apple_url
and outlook_url
(IE does not properly support data-uri links. See #16).Yahoo
, but this is because Yahoo is deprecating IE 11 support and only offers a simplified interface which does not work with the add event URL.I couldn't find an approriate gem or javascript library that did exactly what I wanted. So I decided to scratch my own itch to solve a problem for a startup I'm working on: https://www.littlefutures.org
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/jaredlt/add_to_calendar.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that add_to_calendar demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.