Sha256: aa94ed81e77e842f948f03aff512b4350f4a9ae0ac805ab96c6d7ae72f636cb0

Contents?: true

Size: 1.35 KB

Versions: 7

Compression:

Stored size: 1.35 KB

Contents

module SocialNetworking
  # Sends sms or emails to participants.
  class Notification
    include Sms
    attr_reader :current_participant,
                :mailer,
                :recipient,
                :message_body,
                :subject

    def initialize(
      current_participant:,
      mailer:,
      recipient:,
      message_body:,
      subject:)
      @current_participant = current_participant
      @mailer = mailer
      @message_body = message_body
      @recipient = recipient
      @subject = subject
    end

    def notify
      return if current_participant == recipient
      if recipient.contact_preference == "email"
        send_email
      else
        begin
          send_sms(recipient, message_body)
        rescue Twilio::REST::RequestError => exception
          Raven
            .capture_message "TWILLIO: failed to notify recipient via SMS",
                             extra: {
                               message: exception.message,
                               phone_number: recipient.try(:phone_number),
                               participant: recipient.try(:id)
                             } if defined?(Raven)
        end
      end
    end

    def send_email
      mailer
        .notify(
          recipient: recipient,
          body: message_body,
          subject: subject)
        .deliver_now
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
social_networking-0.11.8 app/models/social_networking/notification.rb
social_networking-0.11.7 app/models/social_networking/notification.rb
social_networking-0.11.6 app/models/social_networking/notification.rb
social_networking-0.11.5 app/models/social_networking/notification.rb
social_networking-0.11.4 app/models/social_networking/notification.rb
social_networking-0.11.3 app/models/social_networking/notification.rb
social_networking-0.11.2 app/models/social_networking/notification.rb