class Icalendar::Google::Calendar

Constants

ENDPOINT

Attributes

google_id[RW]
ical_url[RW]

Public Class Methods

from_google_id(id) click to toggle source
# File lib/icalendar/gcal/google_calendar.rb, line 56
def from_google_id(id)
  url = "#{ENDPOINT}/ical/#{CGI::escape(id)}/public/basic.ics"
  cal = from_ical_url(url)
  cal&.google_id = id
  cal
end
from_ical_url(url) click to toggle source
# File lib/icalendar/gcal/google_calendar.rb, line 46
def from_ical_url(url)
  cid = url[%r{#{ENDPOINT}/ical/(.*?)/public/basic.ics}, 1]
  uri = URI.parse(url)
  res = Net::HTTP.get(uri)
  cal = parse(res).first
  cal&.ical_url  = url
  cal&.google_id = CGI.unescape(cid)
  cal
end

Public Instance Methods

cid() click to toggle source
# File lib/icalendar/gcal/google_calendar.rb, line 12
def cid
  Base64.encode64(google_id.to_s).gsub(%r{\n|=+\Z}, "")
end
eid(event) click to toggle source
# File lib/icalendar/gcal/google_calendar.rb, line 16
def eid(event)
  seed = "#{event.uid.split(%r{@}).first} #{google_id&.slice(0, 28)}"
  Base64.encode64(seed).gsub(%r{\n|=+\Z}, "")
end
event_url(event) click to toggle source
# File lib/icalendar/gcal/google_calendar.rb, line 21
def event_url(event)
  "#{ENDPOINT}/event?eid=#{eid(event)}"
end
events_on(date) click to toggle source
# File lib/icalendar/gcal/google_calendar.rb, line 25
def events_on(date)
  events.select do |event|
    start = tz.utc_to_local event.dtstart.to_datetime
    stop  = tz.utc_to_local event.dtend.to_datetime
    start.to_date <= date && date <= stop.to_date
  end
end
google_url() click to toggle source
# File lib/icalendar/gcal/google_calendar.rb, line 33
def google_url
  "#{ENDPOINT}/r?cid=#{cid}"
end
tz() click to toggle source
# File lib/icalendar/gcal/google_calendar.rb, line 37
def tz
  TZInfo::Timezone.get(x_wr_timezone.first.to_s)
end
webcal_url() click to toggle source
# File lib/icalendar/gcal/google_calendar.rb, line 41
def webcal_url
  ical_url&.sub(%r{\Ahttps?://}, "webcal://")
end