-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
570c4e8
commit b7c96c6
Showing
11 changed files
with
134 additions
and
8 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class CalendarEventsNotify | ||
def initialize | ||
@message = "" | ||
calendar_events_list['items'].try(:each) do |event| | ||
@message += "🗓 #{event.dig('summary')} (#{event.dig('start', 'date')})\n\n" | ||
end | ||
end | ||
|
||
def perform | ||
subscriptions = Subscription.where("notify_type = ?", "台科大行事曆") | ||
subscriptions.each do |subscription| | ||
if @message | ||
LineNotify.send(subscription.user.line_notify_token, message: "\n\n台科大行事曆\n\n近七日台科大活動如下:\n\n#{@message}") | ||
else | ||
LineNotify.send(subscription.user.line_notify_token, message: "\n\n台科大行事曆\n\n近七日沒有任何活動哦!祝你一切順心!") | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def calendar_events_list(duration = 7.days) | ||
calendar_id = "b10730224@gapps.ntust.edu.tw" | ||
url = "https://www.googleapis.com/calendar/v3/calendars/#{calendar_id}/events" | ||
response = Faraday.get(url, { | ||
key: ENV["GOOGLE_API_KEY"], | ||
singleEvents: true, | ||
order_by: "startTime", | ||
time_min: DateTime.now, | ||
time_max: DateTime.now + duration, | ||
}) | ||
JSON.parse response.body | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<div class="container"> | ||
<h1>最近 7 日活動</h1> | ||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th scope="col">ID</th> | ||
<th scope="col">Summary</th> | ||
<th scope="col">Start Date</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @event_list.try(:each) do |event| %> | ||
<tr> | ||
<td><%= "#{event.dig('id')[0..10]}..." %></td> | ||
<td><%= event.dig('summary') %></td> | ||
<td><%= event.dig('start', 'date') %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<%= link_to "發送活動資訊", calendar_notify_path, method: :post, class: "btn btn-primary text-white"%> | ||
</div> |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Use this file to easily define all of your cron jobs. | ||
# | ||
# It's helpful, but not entirely necessary to understand cron before proceeding. | ||
# http://en.wikipedia.org/wiki/Cron | ||
|
||
# Example: | ||
# | ||
# set :output, "/path/to/my/cron_log.log" | ||
# | ||
# every 2.hours do | ||
# command "/usr/bin/some_great_command" | ||
# runner "MyModel.some_method" | ||
# rake "some:great:rake:task" | ||
# end | ||
# | ||
# every 4.days do | ||
# runner "AnotherModel.prune_old_records" | ||
# end | ||
|
||
# Learn more: http://github.com/javan/whenever | ||
set :output, "log/cron_log.log" | ||
env :PATH, ENV['PATH'] | ||
every 1.day, at: '8:00 am' do | ||
rake "line:calendar_notify" | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace :line do | ||
desc "Send Calendar events which occur in 7 days to Subscriber." | ||
task calendar_notify: :environment do | ||
CalendarEventsNotify.new.perform | ||
end | ||
|
||
end |