Created
October 27, 2021 18:06
-
-
Save WagnerMatos/a063543cb7360f81773f3a6931cbac24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# controller | |
class MyController < ApplicationController | |
TEMPLATE_ID = "TEMPLATE_ID" | |
def create | |
authorize ... | |
if send_email | |
redirect_to @referer, success: success_message | |
else | |
redirect_to @referer, error: error_message | |
end | |
end | |
private | |
def set_case_attachable | |
... | |
end | |
def send_email | |
... | |
Notify::Email.new( | |
client_email: "email@email.com", | |
template_id: TEMPLATE_ID, | |
... | |
).deliver_now | |
end | |
def magic_link_url(name, gid) | |
... | |
end | |
def success_message | |
... | |
end | |
def error_message | |
... | |
end | |
end | |
# PORO | |
module Notify | |
class Email | |
include PoroAttributes | |
NOTIFY_API_KEY = SOME_KEY | |
attribute :client_email | |
attribute :template_id | |
attribute :personalisation, default: -> {} | |
def deliver_now | |
send_email | |
rescue Notifications::Client::RequestError | |
raise # Retry elsewhere | |
end | |
private | |
def send_email | |
notify.send_email(...) | |
end | |
def notify | |
@notify ||= | |
ExternalLibrary::Client.new(SOME_API_KEY) | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment