Sha256: 6b9cd305ccdcc8b210a1dc3da52cd7496bcd4c6a117bcf5d0a4557a79d5e1771

Contents?: true

Size: 1.43 KB

Versions: 5

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true
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

5 entries across 5 versions & 1 rubygems

Version Path
social_networking-0.13.3 app/models/social_networking/notification.rb
social_networking-0.13.2 app/models/social_networking/notification.rb
social_networking-0.13.1 app/models/social_networking/notification.rb
social_networking-0.13.0 app/models/social_networking/notification.rb
social_networking-0.12.0 app/models/social_networking/notification.rb