Skip to content

Instantly share code, notes, and snippets.

@WagnerMatos
Created October 27, 2021 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WagnerMatos/a063543cb7360f81773f3a6931cbac24 to your computer and use it in GitHub Desktop.
Save WagnerMatos/a063543cb7360f81773f3a6931cbac24 to your computer and use it in GitHub Desktop.
# 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