Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in goohub.gemspec
gemspec
gem 'icalendar'
1 change: 1 addition & 0 deletions lib/goohub/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
require "#{dir}/get_event.rb"
require "#{dir}/events.rb"
require "#{dir}/post_event.rb"
require "#{dir}/post_ics.rb"
34 changes: 25 additions & 9 deletions lib/goohub/command/post_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,31 @@ class GoohubCLI < Clian::Cli
desc "post_event CALENDAR_ID TITLE START END", "Create an event to CALENDAR_ID"

def post_event(calendar_id, title, start_time, end_time)
event = Google::Apis::CalendarV3::Event.new({
summary: title,
start: {
date_time: start_time,
},
end: {
date_time: end_time,
}
})
if start_time.class == Icalendar::Values::Date then
event = Google::Apis::CalendarV3::Event.new({
summary: title,
start: {
date: start_time,
},
end: {
date: end_time,
}
})

elsif start_time.class == Icalendar::Values::DateTime then
event = Google::Apis::CalendarV3::Event.new({
summary: title,
start: {
date_time: start_time,
},
end: {
date_time: end_time,
}
})
else
puts "Event is not created, because event format is wrong."
return
end
result = client.insert_event(calendar_id, event)
puts "Event created: #{result.html_link}"
end
Expand Down
28 changes: 28 additions & 0 deletions lib/goohub/command/post_ics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'icalendar'

class GoohubCLI < Clian::Cli
################################################################
# Command: post_ics
################################################################
desc "post_ics CALENDAR_ID ICS_FILE", "Create ics file events to CALENDAR_ID"

def post_ics(calendar_id, ics_file)
ics_file = File.open(ics_file)
events = Icalendar::Event.parse(ics_file)
count = 0

puts "Start #{events.size} events post."
events.each { |e|
begin
count = count + 1
post_event(calendar_id, e.summary, e.dtstart, e.dtend)
rescue => error
puts "#########################"
puts "#{error}"
puts "#{e.summary}, #{e.dtstart}, #{e.dtend}"
puts "#########################"
end
}
puts "Done #{count}/#{events.size} events post."
end
end