53 lines
1.5 KiB
Ruby
53 lines
1.5 KiB
Ruby
require 'http'
|
|
|
|
class CalendarService
|
|
|
|
def vacations
|
|
Rails.cache.fetch("vacations", expires_in: 5.minutes) do
|
|
entries("https://static.nocoda.io/remote.php/dav/calendars/pkamin/593FC5A0-746B-48C7-A57B-3A0315976412/?export", "ff00ff")
|
|
end
|
|
end
|
|
|
|
def events
|
|
Rails.cache.fetch("events", expires_in: 5.minutes) do
|
|
entries("https://static.nocoda.io/remote.php/dav/calendars/pkamin/774BE10B-AEAD-4D20-BF09-9C0FFD135E56/?export", "0000ff")
|
|
end
|
|
end
|
|
|
|
def sports
|
|
entries("https://static.nocoda.io/remote.php/dav/calendars").map do |entry|
|
|
|
|
end
|
|
end
|
|
|
|
def entries(url, color)
|
|
#
|
|
a = HTTP.basic_auth(user: 'pkamin', pass: 'QDH*@8fhWekxwWjeX8MQ3H').get(url).body.to_s
|
|
# a = File.read('/Users/pkamin/Desktop/vacation.vcalendar')
|
|
|
|
b = a.split("\r\n")
|
|
|
|
events = []
|
|
e = nil
|
|
|
|
b.each do |line|
|
|
if line == "BEGIN:VEVENT"
|
|
e = Event.new
|
|
e.color = color
|
|
elsif line == "END:VEVENT"
|
|
events << e unless e.nil?
|
|
elsif line.start_with?("DTSTART") && ! e.nil?
|
|
e.begin_at = DateTime.parse(line.split(":").last)
|
|
elsif line.start_with?("DTEND") && ! e.nil?
|
|
e.end_at = DateTime.parse(line.split(":").last)
|
|
e.end_at = e.end_at - 1.minute
|
|
elsif line.start_with?("SUMMARY") && ! e.nil?
|
|
e.name = line.split(":").last
|
|
end
|
|
end
|
|
|
|
events
|
|
end
|
|
end
|
|
|