/add_to_google_cal

AddToGoogleCal is a framework-agnostic view layer library which takes an object and generates an "Add To Google Calendar" URL based on it's attributes. (This could be an ActiveRecord model instance)

Primary LanguageRubyMIT LicenseMIT

AddToGoogleCal

A view layer helper which takes a hash or object (such as an ActiveRecord instance from your database) and generates an "Add To Google Calendar" URL based on it's attributes.

This follows the ISO RFC-2445 calendar standard of using dtstart, dtend, summary, etc. You can customize these fields to match your implementation (ie. start_date, end_date, event_name, etc). Details on this below.

How?

Generic Object:

require 'ostruct'
object = OpenStruct.new({
  :summary => "Super awesome event coming up in 2009, y'all!",
  :dtstart => '2019-03-07'
})

AddToGoogleCal::Builder.new(object).call
=> "https://www.google.com/calendar/render?action=TEMPLATE&dates=20190726T000000Z/20190726T000000Z& ..." (or something like this)

Ruby Hash:

attributes = {
  {
    dtstart: Time.utc(2013, 01, 03, 12, 00),
    dtend:   Time.utc(2013, 01, 03, 14, 00),
    summary: 'This is the Title of the Event'
  }
}

AddToGoogleCal::Builder.new(attributes).call
=> 'https://www.google.com/calendar/render?action=TEMPLATE&dates=20130103T120000Z/20130103T140000Z&text=This+is+the+Title+of+the+Event'

erb might look like:

<%= link_to("Add To Google Calendar", AddToGoogleCal.new(object).call) %>

ActiveRecord:

class Wedding < AR::Base

  has_google_cal

end

Wedding.first.to_google_cal

If your ActiveRecord model uses column names other than dtstart, summary, for example:

Wedding.new(event_name: 'My Event Title')

Use:

has_google_cal {
  :dtstart_field => 'crazy_date_start_column_name',
  :dtend_field   => 'my_event_end_time',
  :summary_field => 'event_name'
}

Installation

Add this line to your application's Gemfile:

gem 'add_to_google_cal'

And then execute:

$ bundle

Or install it yourself as:

$ gem install add_to_google_cal

TODO:

  • Handle converting various types of date/time objects
    • Finish the argument validation for required fields
  • Support the following custom column names in has_google_cal AR mixin:
    • location
    • description
  • Support objects / structs

Thanks To

@pcreux and everyone else who has colloborated / paired on this project.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Why?

I was working on Handcrafted Video Wedding Invites and this project was born out of a need to allow wedding guests quickly adding a wedding event to their Google Calendar.

http://www.craftedtoyou.com/