gem "hcaptcha"
# subscribers
gem "stripe"
+# Scheduling
+gem "whenever", require: false
# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"
#api stuff
xpath (~> 3.2)
childprocess (5.1.0)
logger (~> 1.5)
+ chronic (0.10.2)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
crass (1.0.6)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
+ whenever (1.0.0)
+ chronic (>= 0.6.3)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.18)
stripe
tzinfo-data
web-console
+ whenever
BUNDLED WITH
2.5.11
--- /dev/null
+class WeeklyBookmarksDigestJob < ApplicationJob
+ queue_as :default
+
+ def perform(*args)
+ start_date = 1.week.ago.beginning_of_week
+ end_date = Time.current.end_of_week
+ bookmarks = Post.bookmarks.where(created_at: start_date..end_date)
+ # or do User.find_each do |user| for everyone, but that'll break fastmail
+ DigestMailer.weekly_bookmarks_digest(User.first, bookmarks).deliver_now
+ end
+end
--- /dev/null
+class DigestMailer < ApplicationMailer
+ # Subject can be set in your I18n file at config/locales/en.yml
+ # with the following lookup:
+ #
+ # en.digest_mailer.weekly_bookmarks_digest.subject
+ #
+ def weekly_bookmarks_digest(user, bookmarks)
+ @user = user
+ @bookmarks = bookmarks
+ mail(to: @user.email, subject: 'mind reader :: weekly bookmarks digest')
+ end
+end
--- /dev/null
+<h1>Your weekly bookmarks digest</h1>
+
+<p>Hello <%= @user.first_name %>,</p>
+
+<p>Here are the bookmarks added this week:</p>
+
+<ul>
+ <% @bookmarks.each do |bookmark| %>
+ <li>
+ <strong><%= link_to bookmark.title, bookmark.url %></strong>
+ <% if bookmark.content.present? %>
+ <br><em><%= bookmark.content %></em>
+ <% end %>
+ </li>
+ <% end %>
+</ul>
+
+<p>Have a great weekend!</p>
\ No newline at end of file
--- /dev/null
+# 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
+
+every :friday, at: '4pm' do
+ rake "bookmarks_digest:send_weekly"
+end
\ No newline at end of file
--- /dev/null
+namespace :bookmarks_digest do
+ desc "Send weekly bookmarks digest"
+ task send_weekly: :environment do
+ WeeklyBookmarksDigestJob.perform_later
+ end
+end
\ No newline at end of file
require "test_helper"
-class PostTest < ActiveSupport::TestCase
+class WeeklyBookmarksDigestJobTest < ActiveJob::TestCase
# test "the truth" do
# assert true
# end
--- /dev/null
+require "test_helper"
+
+class DigestMailerTest < ActionMailer::TestCase
+ test "weekly_bookmarks_digest" do
+ mail = DigestMailer.weekly_bookmarks_digest
+ assert_equal "Weekly bookmarks digest", mail.subject
+ assert_match "Hi", mail.body.encoded
+ end
+end
--- /dev/null
+# Preview all emails at http://localhost:3000/rails/mailers/digest_mailer
+class DigestMailerPreview < ActionMailer::Preview
+ # Preview this email at http://localhost:3000/rails/mailers/digest_mailer/weekly_bookmarks_digest
+ def weekly_bookmarks_digest
+ DigestMailer.weekly_bookmarks_digest
+ end
+end