Created
July 18, 2017 23:11
-
-
Save guidomb/677df830562a97344f141c39def30102 to your computer and use it in GitHub Desktop.
An example of an integration using a Ruby DSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
event_bus.calendar.new_event do |event| | |
# Schedule a task to be executed once the calendar event | |
# has finished | |
schedule_task(on: event.end_date) do |date| | |
# Utility function that gets a Logger::Activity | |
# object from the calendar event. It tries to | |
# infer it based on the metada of the event | |
activity = logger.activity(for: event) | |
event.participants.each do |participant| | |
slack_user = find_slack_user(email: participant.email) | |
# Ask user through Slack if he or she participated in the event. Wait | |
# for the response for two hours. Otherwise asume that the person went | |
# to the event. | |
slack_user.ask(message: "Did you go to #{event.title}?", wait_time: 2 * 60 * 60) do |participated| | |
return unless participated | |
# If the user participated in the event we log the event duration | |
logger_entry = LoggerEntry.new( | |
user: participant.email | |
duration: event.duration | |
activity: activity | |
) | |
# We notify the user through slack that the event has been logged | |
logger.log(logger_entry) do | |
slack_user.tell("#{duration / 60.0} hours have been logged to #{activity}") | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment