fix: dolist module/class mismatch
This commit is contained in:
parent
2ad8ccc310
commit
f7a80eb905
5 changed files with 308 additions and 304 deletions
|
@ -1,6 +1,7 @@
|
|||
require "support/jsv"
|
||||
|
||||
class Dolist::API
|
||||
module Dolist
|
||||
class API
|
||||
CONTACT_URL = "https://apiv9.dolist.net/v1/contacts/read?AccountID=%{account_id}"
|
||||
EMAIL_LOGS_URL = "https://apiv9.dolist.net/v1/statistics/email/sendings/transactional/search?AccountID=%{account_id}"
|
||||
EMAIL_KEY = 7
|
||||
|
@ -311,4 +312,5 @@ class Dolist::API
|
|||
Dolist::Base64File.new(field_name:, filename: attachment.filename, mime_type: attachment.mime_type, content: attachment_base64)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
21
app/lib/dolist/api_sender.rb
Normal file
21
app/lib/dolist/api_sender.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
module Dolist
|
||||
class APISender
|
||||
def initialize(mail); end
|
||||
|
||||
def deliver!(mail)
|
||||
client = Dolist::API.new
|
||||
response = client.send_email(mail)
|
||||
if response&.dig("Result")
|
||||
mail.message_id = response.dig("Result")
|
||||
else
|
||||
_, invalid_contact_status = client.ignorable_error?(response, mail)
|
||||
|
||||
if invalid_contact_status
|
||||
raise Dolist::IgnorableError.new("DoList delivery error. contact unreachable: #{invalid_contact_status}")
|
||||
else
|
||||
fail "DoList delivery error. Body: #{response}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
3
app/lib/dolist/ignorable_error.rb
Normal file
3
app/lib/dolist/ignorable_error.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
module Dolist
|
||||
class IgnorableError < StandardError; end
|
||||
end
|
12
app/lib/dolist/smtp.rb
Normal file
12
app/lib/dolist/smtp.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
module Dolist
|
||||
class SMTP < ::Mail::SMTP
|
||||
def deliver!(mail)
|
||||
mail.from(ENV['DOLIST_NO_REPLY_EMAIL'])
|
||||
mail.sender(ENV['DOLIST_NO_REPLY_EMAIL'])
|
||||
mail['X-ACCOUNT-ID'] = Rails.application.secrets.dolist[:account_id]
|
||||
mail['X-Dolist-Sending-Type'] = 'TransactionalService' # send even if the target is not active
|
||||
|
||||
super(mail)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,39 +1,5 @@
|
|||
ActiveSupport.on_load(:action_mailer) do
|
||||
module Dolist
|
||||
class IgnorableError < StandardError
|
||||
end
|
||||
|
||||
class SMTP < ::Mail::SMTP
|
||||
def deliver!(mail)
|
||||
mail.from(ENV['DOLIST_NO_REPLY_EMAIL'])
|
||||
mail.sender(ENV['DOLIST_NO_REPLY_EMAIL'])
|
||||
mail['X-ACCOUNT-ID'] = Rails.application.secrets.dolist[:account_id]
|
||||
mail['X-Dolist-Sending-Type'] = 'TransactionalService' # send even if the target is not active
|
||||
|
||||
super(mail)
|
||||
end
|
||||
end
|
||||
|
||||
class ApiSender
|
||||
def initialize(mail); end
|
||||
|
||||
def deliver!(mail)
|
||||
client = Dolist::API.new
|
||||
response = client.send_email(mail)
|
||||
if response&.dig("Result")
|
||||
mail.message_id = response.dig("Result")
|
||||
else
|
||||
_, invalid_contact_status = client.ignorable_error?(response, mail)
|
||||
|
||||
if invalid_contact_status
|
||||
raise Dolist::IgnorableError.new("DoList delivery error. contact unreachable: #{invalid_contact_status}")
|
||||
else
|
||||
fail "DoList delivery error. Body: #{response}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
require "dolist/smtp"
|
||||
|
||||
ActionMailer::Base.add_delivery_method :dolist_smtp, Dolist::SMTP
|
||||
ActionMailer::Base.dolist_smtp_settings = {
|
||||
|
@ -45,5 +11,5 @@ ActiveSupport.on_load(:action_mailer) do
|
|||
enable_starttls_auto: true
|
||||
}
|
||||
|
||||
ActionMailer::Base.add_delivery_method :dolist_api, Dolist::ApiSender
|
||||
ActionMailer::Base.add_delivery_method :dolist_api, Dolist::APISender
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue