Class: VANotify::NotificationEmail::SavedClaim
- Inherits:
-
Object
- Object
- VANotify::NotificationEmail::SavedClaim
- Defined in:
- lib/va_notify/notification_email/saved_claim.rb
Overview
general SavedClaim email notification function
an entry should be in Settings.vanotify.services - config/settings.yml
Direct Known Subclasses
Instance Attribute Summary collapse
-
#claim ⇒ Object
readonly
private
Returns the value of attribute claim.
-
#email_template_id ⇒ Object
readonly
private
Returns the value of attribute email_template_id.
-
#email_type ⇒ Object
readonly
private
Returns the value of attribute email_type.
Instance Method Summary collapse
-
#claim_class ⇒ Object
private
the type of SavedClaim to be queried.
-
#deliver(email_type, at: nil) ⇒ ClaimVANotification
deliver a notification for claim.
-
#email ⇒ Object
private
retrieve the email from the claim - specific claim types should have an ‘email` function defined - or should inherit this class and override this function.
-
#enqueue_email(email_template_id, at) ⇒ Object
private
schedule sending of email at future date.
-
#flipper_enabled?(flipper_id) ⇒ Boolean
private
flipper exists and is enabled.
-
#initialize(saved_claim_id, service_name: nil) ⇒ SavedClaim
constructor
constructor.
-
#monitoring ⇒ Object
private
create the tags and context for monitoring.
-
#personalization ⇒ Object
private
assemble details for personalization in the email - specific claim types should inherit this class and override this function.
-
#send_email(email_template_id) ⇒ Object
private
send the notification email immediately.
-
#valid_attempt? ⇒ Boolean
private
check prerequisites before attempting to send the email.
-
#vanotify_service ⇒ Object
private
return or default the service_name to be used.
Constructor Details
#initialize(saved_claim_id, service_name: nil) ⇒ SavedClaim
constructor
30 31 32 33 |
# File 'lib/va_notify/notification_email/saved_claim.rb', line 30 def initialize(saved_claim_id, service_name: nil) @claim = claim_class.find(saved_claim_id) @vanotify_service = service_name end |
Instance Attribute Details
#claim ⇒ Object (readonly, private)
Returns the value of attribute claim.
63 64 65 |
# File 'lib/va_notify/notification_email/saved_claim.rb', line 63 def claim @claim end |
#email_template_id ⇒ Object (readonly, private)
Returns the value of attribute email_template_id.
63 64 65 |
# File 'lib/va_notify/notification_email/saved_claim.rb', line 63 def email_template_id @email_template_id end |
#email_type ⇒ Object (readonly, private)
Returns the value of attribute email_type.
63 64 65 |
# File 'lib/va_notify/notification_email/saved_claim.rb', line 63 def email_type @email_type end |
Instance Method Details
#claim_class ⇒ Object (private)
the type of SavedClaim to be queried
66 67 68 |
# File 'lib/va_notify/notification_email/saved_claim.rb', line 66 def claim_class ::SavedClaim end |
#deliver(email_type, at: nil) ⇒ ClaimVANotification
deliver a notification for claim
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/va_notify/notification_email/saved_claim.rb', line 44 def deliver(email_type, at: nil) @email_type = email_type @email_template_id = valid_attempt? return unless email_template_id at ? enqueue_email(email_template_id, at) : send_email(email_template_id) db_record = claim.insert_notification(email_template_id) , context = monitoring VANotify::NotificationEmail.monitor_deliver_success(tags:, context:) db_record rescue => e , context = monitoring VANotify::NotificationEmail.monitor_send_failure(e&., tags:, context:) end |
#email ⇒ Object (private)
retrieve the email from the claim
-
specific claim types should have an ‘email` function defined
-
or should inherit this class and override this function
145 146 147 |
# File 'lib/va_notify/notification_email/saved_claim.rb', line 145 def email claim.email end |
#enqueue_email(email_template_id, at) ⇒ Object (private)
schedule sending of email at future date
122 123 124 125 126 127 128 129 |
# File 'lib/va_notify/notification_email/saved_claim.rb', line 122 def enqueue_email(email_template_id, at) VANotify::EmailJob.perform_at( at, email, email_template_id, personalization ) end |
#flipper_enabled?(flipper_id) ⇒ Boolean (private)
flipper exists and is enabled
77 78 79 |
# File 'lib/va_notify/notification_email/saved_claim.rb', line 77 def flipper_enabled?(flipper_id) !flipper_id || (flipper_id && Flipper.enabled?(:"#{flipper_id}")) end |
#monitoring ⇒ Object (private)
create the tags and context for monitoring
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/va_notify/notification_email/saved_claim.rb', line 104 def monitoring = ["service_name:#{vanotify_service}", "form_id:#{claim.form_id}", "email_template_id:#{email_template_id}"] context = { form_id: claim.form_id, saved_claim_id: claim.id, service_name: vanotify_service, email_type:, email_template_id: } [, context] end |
#personalization ⇒ Object (private)
assemble details for personalization in the email
-
specific claim types should inherit this class and override this function
151 152 153 154 155 156 |
# File 'lib/va_notify/notification_email/saved_claim.rb', line 151 def personalization { 'date_submitted' => claim.submitted_at, 'confirmation_number' => claim.confirmation_number } end |
#send_email(email_template_id) ⇒ Object (private)
send the notification email immediately
134 135 136 137 138 139 140 |
# File 'lib/va_notify/notification_email/saved_claim.rb', line 134 def send_email(email_template_id) VANotify::EmailJob.perform_async( email, email_template_id, personalization ) end |
#valid_attempt? ⇒ Boolean (private)
check prerequisites before attempting to send the email
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/va_notify/notification_email/saved_claim.rb', line 82 def valid_attempt? config = Settings.vanotify.services[vanotify_service] raise ArgumentError, "Invalid service_name '#{vanotify_service}'" unless config email_config = config.email[email_type] raise ArgumentError, "Invalid email_type '#{email_type}'" unless email_config @email_template_id = email_config.template_id raise VANotify::NotificationEmail::FailureToSend, 'Invalid template' unless email_template_id raise VANotify::NotificationEmail::FailureToSend, 'Missing email' if email.blank? is_enabled = flipper_enabled?(email_config.flipper_id) already_sent = claim.va_notification?(email_config.template_id) if already_sent , context = monitoring VANotify::NotificationEmail.monitor_duplicate_attempt(tags:, context:) end email_template_id if is_enabled && !already_sent end |
#vanotify_service ⇒ Object (private)
return or default the service_name to be used
71 72 73 |
# File 'lib/va_notify/notification_email/saved_claim.rb', line 71 def vanotify_service @vanotify_service ||= claim&.form_id&.downcase&.gsub(/-/, '_') end |