Sha256: 4d6c9995ad1f8970a6b67da903cf3e6b4f6771eb1d87365090452ff3ffe5efec

Contents?: true

Size: 1.92 KB

Versions: 13

Compression:

Stored size: 1.92 KB

Contents

class Mailer < ApplicationMailer
  include Roadie::Rails::Automatic
  add_template_helper(HackathonManagerHelper)

  default from: Rails.configuration.hackathon['email_from']

  def bulk_message_email(message_id, user_id, message = nil)
    @message = message || Message.find_by_id(message_id)
    @user    = User.find_by_id(user_id)
    return if @user.blank? || @message.blank?
    mail(
      to: pretty_email(@user.full_name, @user.email),
      subject: @message.subject
    )
  end

  def incomplete_reminder_email(user_id)
    @user = User.find_by_id(user_id)
    return if @user.blank? || @user.admin? || @user.questionnaire || Time.now.to_date > Rails.configuration.hackathon['last_day_to_apply']
    mail(
      to: @user.email,
      subject: "Incomplete Application"
    )
  end

  def bus_captain_confirmation_email(bus_list_id, user_id)
    @user = User.find_by_id(user_id)
    @questionnaire = @user.questionnaire
    @bus_list = BusList.find_by_id(bus_list_id)
    return if @user.blank? || @user.questionnaire.blank? || !@user.questionnaire.is_bus_captain? || @bus_list.blank?
    mail_questionnaire("You're a bus captain!")
  end

  def bus_list_update_email(questionnaire_id)
    @questionnaire = Questionnaire.find_by_id(questionnaire_id)
    @bus_list = @questionnaire.bus_list
    return if @questionnaire.blank? || @questionnaire.user.blank? || @bus_list.blank?
    mail_questionnaire("Bus Update")
  end

  private

  def pretty_email(name, email)
    return email if name.blank?
    "\"#{name}\" <#{email}>"
  end

  def mail_questionnaire(subject, sparkpost_data = {})
    mail(
      to: pretty_email(@questionnaire.full_name, @questionnaire.user.email),
      subject: subject,
      sparkpost_data: sparkpost_data
    )
  rescue SparkPostRails::DeliveryException => e
    error_code_to_not_retry = [
      "1902" # Generation rejection
    ]
    raise e unless e.blank? || error_code_to_not_retry.include?(e.service_code)
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
hackathon_manager-0.13.12 app/mailers/mailer.rb
hackathon_manager-0.13.11 app/mailers/mailer.rb
hackathon_manager-0.13.10 app/mailers/mailer.rb
hackathon_manager-0.13.9 app/mailers/mailer.rb
hackathon_manager-0.13.8 app/mailers/mailer.rb
hackathon_manager-0.13.7 app/mailers/mailer.rb
hackathon_manager-0.13.6 app/mailers/mailer.rb
hackathon_manager-0.13.5 app/mailers/mailer.rb
hackathon_manager-0.13.4 app/mailers/mailer.rb
hackathon_manager-0.13.3 app/mailers/mailer.rb
hackathon_manager-0.13.2 app/mailers/mailer.rb
hackathon_manager-0.13.1 app/mailers/mailer.rb
hackathon_manager-0.13.0 app/mailers/mailer.rb