diff --git a/Gemfile b/Gemfile index 98368d5..b2538ea 100644 --- a/Gemfile +++ b/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' diff --git a/Gemfile.lock b/Gemfile.lock index 48e7673..5c585f4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/app/controllers/birthdays_controller.rb b/app/controllers/birthdays_controller.rb index 726c3b6..a1aa018 100644 --- a/app/controllers/birthdays_controller.rb +++ b/app/controllers/birthdays_controller.rb @@ -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 diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb new file mode 100644 index 0000000..b7cf135 --- /dev/null +++ b/app/mailers/user_mailer.rb @@ -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 diff --git a/app/views/birthdays/do_mailing.html.erb b/app/views/birthdays/do_mailing.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/user_mailer/next_weeks_birthday_notification.html.erb b/app/views/user_mailer/next_weeks_birthday_notification.html.erb new file mode 100644 index 0000000..4de37e9 --- /dev/null +++ b/app/views/user_mailer/next_weeks_birthday_notification.html.erb @@ -0,0 +1,5 @@ +<% @birthday_contacts.each do |contact| %> +
+ <%= contact.birth_day.to_s %>.<%= contact.birth_month.to_s %>.: <%= contact.firstname %> <%= contact.lastname %> +
+<% end %> diff --git a/config/routes.rb b/config/routes.rb index bda69a8..1b85bf1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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: diff --git a/test/functional/user_mailer_test.rb b/test/functional/user_mailer_test.rb new file mode 100644 index 0000000..736b3a4 --- /dev/null +++ b/test/functional/user_mailer_test.rb @@ -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