FogBugz #75: start sending notification mails for birthdays in the next 7 days.
This commit is contained in:
parent
42b29f5260
commit
6f333f76b7
8 changed files with 60 additions and 11 deletions
6
Gemfile
6
Gemfile
|
|
@ -9,11 +9,13 @@ gem 'rake', '0.8.7'
|
|||
# Bundle edge Rails instead:
|
||||
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
||||
|
||||
gem 'mysql2', '0.2.7'
|
||||
#gem 'mysql2', '0.3.7'
|
||||
gem 'sqlite3'
|
||||
|
||||
# https://github.com/plataformatec/devise
|
||||
gem 'devise', '1.2.1'
|
||||
gem 'bcrypt-ruby', '2.1.4'
|
||||
# gem 'bcrypt-ruby', '2.1.4'
|
||||
gem 'bcrypt-ruby'
|
||||
|
||||
# https://github.com/ryanb/cancan
|
||||
gem 'cancan', '1.6.5'
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ GEM
|
|||
addressable (2.2.6)
|
||||
arel (2.0.10)
|
||||
bcrypt-ruby (2.1.4)
|
||||
bcrypt-ruby (2.1.4-x86-mingw32)
|
||||
builder (2.1.2)
|
||||
cancan (1.6.5)
|
||||
capistrano (2.5.21)
|
||||
|
|
@ -49,7 +48,7 @@ GEM
|
|||
faraday (0.6.1)
|
||||
addressable (~> 2.2.4)
|
||||
multipart-post (~> 1.1.0)
|
||||
rack (>= 1.1.0, < 2)
|
||||
rack (< 2, >= 1.1.0)
|
||||
faraday_middleware (0.6.5)
|
||||
faraday (~> 0.6.0)
|
||||
hashie (1.0.0)
|
||||
|
|
@ -79,7 +78,6 @@ GEM
|
|||
rack (>= 1.0.0)
|
||||
rack-test (0.5.7)
|
||||
rack (>= 1.0)
|
||||
railroady (1.0.2)
|
||||
rails (3.0.9)
|
||||
actionmailer (= 3.0.9)
|
||||
actionpack (= 3.0.9)
|
||||
|
|
@ -121,7 +119,6 @@ DEPENDENCIES
|
|||
capistrano (= 2.5.21)
|
||||
devise (= 1.2.1)
|
||||
mysql2 (= 0.2.7)
|
||||
railroady
|
||||
rails (= 3.0.9)
|
||||
rake (= 0.8.7)
|
||||
twitter (= 1.6.0)
|
||||
|
|
|
|||
|
|
@ -1,17 +1,37 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
class BirthdaysController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
before_filter :authenticate_user!, :except => [:do_mailing]
|
||||
|
||||
def index
|
||||
@birthdays = get_next_weeks_birthdays
|
||||
end
|
||||
|
||||
# curl --verbose --header "Accept: application/html" --header "Content-type: application/html" --request POST --data "" http://contactorama.dev/birthdays/do_mailing
|
||||
# wget --post-data '' http://contact-o-rama.de/birthdays/do_mailing
|
||||
# crontab:
|
||||
# 30 3 * * * wget --post-data '' http://contact-o-rama.de/birthdays/do_mailing
|
||||
def do_mailing
|
||||
birthdays = get_next_weeks_birthdays
|
||||
birthdays.each do |bday|
|
||||
logger.info "............< do_mailing: " + bday.firstname + " " + bday.lastname + " >.............."
|
||||
UserMailer.next_weeks_birthday_notification(birthdays).deliver
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_next_weeks_birthdays
|
||||
n = Date.today
|
||||
e = Date.today + 7.days
|
||||
|
||||
# two cases here: now + 7days iis still the same month. or it's not.
|
||||
if n.month == e.month
|
||||
@birthdays = Contact.where("birth_month = ? AND birth_day <= ? AND birth_day >= ?",
|
||||
birthdays = Contact.where("birth_month = ? AND birth_day <= ? AND birth_day >= ?",
|
||||
e.month, e.day, n.day)
|
||||
else
|
||||
@birthdays = Contact.where("(birth_month = ? AND birth_day <= ?) OR (birth_month = ? AND birth_day >= ?)",
|
||||
birthdays = Contact.where("(birth_month = ? AND birth_day <= ?) OR (birth_month = ? AND birth_day >= ?)",
|
||||
e.month, e.day, n.month, n.day)
|
||||
end
|
||||
end
|
||||
birthdays
|
||||
end
|
||||
end
|
||||
|
|
|
|||
13
app/mailers/user_mailer.rb
Normal file
13
app/mailers/user_mailer.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# -*- coding: iso-8859-1 -*-
|
||||
class UserMailer < ActionMailer::Base
|
||||
default :from => "info@contact-o-rama.com"
|
||||
|
||||
def next_weeks_birthday_notification(birthdays)
|
||||
logger.debug "----------------< we don't send no email, yet >----------------------"
|
||||
@birthday_contacts = birthdays
|
||||
mail(:to => "contact-o-rama@gasbottle-county.eu", :subject => "Contact-o-Rama: Geburtstage in den nächsten 7 Tagen.")
|
||||
birthdays.each do |contact|
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
0
app/views/birthdays/do_mailing.html.erb
Normal file
0
app/views/birthdays/do_mailing.html.erb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<% @birthday_contacts.each do |contact| %>
|
||||
<p>
|
||||
<%= contact.birth_day.to_s %>.<%= contact.birth_month.to_s %>.: <%= contact.firstname %> <%= contact.lastname %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
|
@ -3,7 +3,11 @@ ContactORama::Application.routes.draw do
|
|||
devise_for :users
|
||||
resources :users
|
||||
|
||||
resources :birthdays
|
||||
resources :birthdays do
|
||||
collection do
|
||||
post :do_mailing
|
||||
end
|
||||
end
|
||||
resources :contacts
|
||||
|
||||
# The priority is based upon order of creation:
|
||||
|
|
|
|||
8
test/functional/user_mailer_test.rb
Normal file
8
test/functional/user_mailer_test.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
class UserMailerTest < ActionMailer::TestCase
|
||||
# replace this with your real tests
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue