# AddToCalendar A ruby gem to generate 'Add To Calendar' URLs for Apple, Google, Office 365, Outlook, Outlook.com and Yahoo calendars. If this gem brings you some value feel free to buy me a coffee :) [![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/P5P71PK9T) ## Installation Add this line to your application's Gemfile: ```ruby gem 'add_to_calendar' ``` And then execute: $ bundle Or install it yourself as: $ gem install add_to_calendar ## Requirements - Ruby 2.0 or higher ## Usage ```ruby # 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.office365_url #=> "https://outlook.office.com/calendar/0/deeplink/compose?path=/calendar/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/deeplink/compose?path=/calendar/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" # apple_url and outlook_url are simply helper methods that call ical_url @cal.apple_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" @cal.outlook_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" ``` ### Creating HTML links ```erb Add to Google Calendar Add to Yahoo Calendar Download iCal ``` ### Event attributes ```ruby 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 } cal = AddToCalendar::URLs.new(event_attributes) ``` | Attribute | Required? | Class | Notes | | -----------------------|-----------|------------|-------| | start_datetime | Yes | Time | | | end_datetime | No | Time |