add: template email message

This commit is contained in:
yystopf 2021-09-22 14:25:56 +08:00
parent 53212975f1
commit e5199425ee
24 changed files with 348 additions and 21 deletions

View File

@ -1,5 +1,5 @@
class Admins::MessageTemplatesController < Admins::BaseController
before_action :get_template, only: [:edit,:update, :destroy]
before_action :get_template, only: [:edit, :update, :destroy]
def index
message_templates = MessageTemplate.group(:type).count.keys
@ -30,8 +30,8 @@ class Admins::MessageTemplatesController < Admins::BaseController
end
private
def message_template_params
params.require(:message_template).permit!
def message_template_params
params.require(@message_template.type.split("::").join("_").underscore.to_sym).permit!
end
def get_template

View File

@ -20,6 +20,8 @@ class SendTemplateMessageJob < ApplicationJob
receivers = User.where(id: issue&.assigned_to_id).where.not(id: operator&.id)
receivers_string, content, notification_url = MessageTemplate::IssueAssigned.get_message_content(receivers, operator, issue)
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_id: issue.id})
receivers_email_string, email_content, notification_url = MessageTemplate::IssueAssigned.get_email_message_content(receivers, operator, issue)
Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source)
when 'IssueAssignerExpire'
issue_id = args[0]
issue = Issue.find_by_id(issue_id)
@ -65,6 +67,8 @@ class SendTemplateMessageJob < ApplicationJob
receivers = User.where(id: user.id)
receivers_string, content, notification_url = MessageTemplate::OrganizationJoined.get_message_content(receivers, organization)
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {user_id: user.id, organization_id: organization.id})
receivers_email_string, email_content, notification_url = MessageTemplate::OrganizationJoined.get_email_message_content(receivers, organization)
Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source)
when 'OrganizationLeft'
user_id, organization_id = args[0], args[1]
user = User.find_by_id(user_id)
@ -73,6 +77,8 @@ class SendTemplateMessageJob < ApplicationJob
receivers = User.where(id: user.id)
receivers_string, content, notification_url = MessageTemplate::OrganizationLeft.get_message_content(receivers, organization)
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {user_id: user.id, organization_id: organization.id})
receivers_email_string, email_content, notification_url = MessageTemplate::OrganizationLeft.get_email_message_content(receivers, organization)
Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source)
when 'OrganizationRole'
user_id, organization_id, role = args[0], args[1], args[2]
user = User.find_by_id(user_id)
@ -81,6 +87,8 @@ class SendTemplateMessageJob < ApplicationJob
receivers = User.where(id: user.id)
receivers_string, content, notification_url = MessageTemplate::OrganizationRole.get_message_content(receivers, organization, role)
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {user_id: user.id, organization_id: organization.id, role: role})
receivers_email_string, email_content, notification_url = MessageTemplate::OrganizationRole.get_email_message_content(receivers, organization, role)
Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source)
when 'ProjectIssue'
operator_id, issue_id = args[0], args[1]
operator = User.find_by_id(operator_id)
@ -90,6 +98,8 @@ class SendTemplateMessageJob < ApplicationJob
followers = [] # TODO
receivers_string, content, notification_url = MessageTemplate::ProjectIssue.get_message_content(managers, followers, operator, issue)
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_id: issue.id})
receivers_email_string, email_content, notification_url = MessageTemplate::ProjectIssue.get_email_message_content(managers, followers, operator, issue)
Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source)
when 'ProjectJoined'
operator_id, user_id, project_id = args[0], args[1], args[2]
operator = User.find_by_id(operator_id)
@ -99,6 +109,8 @@ class SendTemplateMessageJob < ApplicationJob
receivers = User.where(id: user.id).where.not(id: operator&.id)
receivers_string, content, notification_url = MessageTemplate::ProjectJoined.get_message_content(receivers, project)
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, user_id: user.id, project_id: project.id})
receivers_emal_string, email_content, notification_url = MessageTemplate::ProjectJoined.get_email_message_content(receivers, project)
Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source)
when 'ProjectLeft'
operator_id, user_id, project_id = args[0], args[1], args[2]
operator = User.find_by_id(operator_id)
@ -108,6 +120,8 @@ class SendTemplateMessageJob < ApplicationJob
receivers = User.where(id: user.id).where.not(id: operator&.id)
receivers_string, content, notification_url = MessageTemplate::ProjectLeft.get_message_content(receivers, project)
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, user_id: user.id, project_id: project.id})
receivers_email_string, email_content, notification_url = MessageTemplate::ProjectLeft.get_email_message_content(receivers, project)
Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source)
when 'ProjectMemberJoined'
operator_id, user_id, project_id = args[0], args[1], args[2]
operator = User.find_by_id(operator_id)
@ -117,6 +131,8 @@ class SendTemplateMessageJob < ApplicationJob
receivers = project&.all_managers.where.not(id: operator&.id)
receivers_string, content, notification_url = MessageTemplate::ProjectMemberJoined.get_message_content(receivers, user, project)
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, user_id: user.id, project_id: project.id})
receivers_email_string, email_content, notification_url = MessageTemplate::ProjectMemberJoined.get_email_message_content(receivers, user, project)
Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source)
when 'ProjectMemberLeft'
operator_id, user_id, project_id = args[0], args[1], args[2]
operator = User.find_by_id(operator_id)
@ -126,6 +142,8 @@ class SendTemplateMessageJob < ApplicationJob
receivers = project&.all_managers.where.not(id: operator&.id)
receivers_string, content, notification_url = MessageTemplate::ProjectMemberLeft.get_message_content(receivers, user, project)
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, user_id: user.id, project_id: project.id})
receivers_email_string, email_content, notification_url = MessageTemplate::ProjectMemberLeft.get_email_message_content(receivers, user, project)
Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source)
when 'ProjectPullRequest'
operator_id, pull_request_id = args[0], args[1]
operator = User.find_by_id(operator_id)
@ -135,6 +153,8 @@ class SendTemplateMessageJob < ApplicationJob
followers = [] # TODO
receivers_string, content, notification_url = MessageTemplate::ProjectPullRequest.get_message_content(managers, followers, operator, pull_request)
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, pull_request_id: pull_request.id})
receivers_email_string, email_content, notification_url = MessageTemplate::ProjectPullRequest.get_email_message_content(managers, followers, operator, pull_request)
Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source)
when 'ProjectRole'
operator_id, user_id, project_id, role = args[0], args[1], args[2], args[3]
operator = User.find_by_id(operator_id)
@ -144,6 +164,8 @@ class SendTemplateMessageJob < ApplicationJob
receivers = User.where(id: user.id).where.not(id: operator&.id)
receivers_string, content, notification_url = MessageTemplate::ProjectRole.get_message_content(receivers, project, role)
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, user_id: user.id, project_id: project.id, role: role})
receivers_email_string, email_content, notification_url = MessageTemplate::ProjectRole.get_email_message_content(receivers, project, role)
Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source)
when 'ProjectSettingChanged'
operator_id, project_id, change_params = args[0], args[1], args[2]
operator = User.find_by_id(operator_id)
@ -152,6 +174,8 @@ class SendTemplateMessageJob < ApplicationJob
receivers = project.all_managers.where.not(id: operator&.id)
receivers_string, content, notification_url = MessageTemplate::ProjectSettingChanged.get_message_content(receivers, operator, project, change_params.symbolize_keys)
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, project_id: project.id, change_params: change_params})
receivers_email_string, email_content, notification_url = MessageTemplate::ProjectSettingChanged.get_email_message_content(receivers, operator, project, change_params.symbolize_keys)
Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source)
when 'PullRequestAssigned'
operator_id, pull_request_id = args[0], args[1]
operator = User.find_by_id(operator_id)
@ -161,6 +185,8 @@ class SendTemplateMessageJob < ApplicationJob
receivers = User.where(id: issue&.assigned_to_id).where.not(id: operator&.id)
receivers_string, content, notification_url = MessageTemplate::PullRequestAssigned.get_message_content(receivers, operator, pull_request)
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, pull_request_id: pull_request.id})
receivers_email_string, email_content, notification_url = MessageTemplate::PullRequestAssigned.get_email_message_content(receivers, operator, pull_request)
Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source)
when 'PullRequestAtme'
receivers, operator_id, pull_request_id = args[0], args[1], args[2]
operator = User.find_by_id(operator_id)

View File

@ -11,7 +11,7 @@
# notification_url :string(255)
#
class MessageTemplate <ApplicationRecord
class MessageTemplate < ApplicationRecord
def self.build_init_data
self.create(type: 'MessageTemplate::FollowedTip', sys_notice: '<b>{nickname}</b> 关注了你', notification_url: '{baseurl}/{login}')
@ -53,6 +53,10 @@ class MessageTemplate <ApplicationRecord
self.last&.sys_notice
end
def self.email
self.last&.email
end
def self.notification_url
self.last&.notification_url.gsub('{baseurl}', base_url)
end
@ -65,6 +69,10 @@ class MessageTemplate <ApplicationRecord
receivers.pluck(:id).join(",")
end
def self.receivers_email_string(receivers)
receivers.pluck(:mail).join(",")
end
def simple_type
self.type.split("::")[-1]
end

View File

@ -25,4 +25,15 @@ class MessageTemplate::IssueAssigned < MessageTemplate
Rails.logger.info("MessageTemplate::IssueAssigned.get_message_content [ERROR] #{e}")
return '', '', ''
end
def self.get_email_message_content(receivers, operator, issue)
project = issue&.project
owner = project&.owner
content = email.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name).gsub('{title}', issue&.subject)
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s)
return receivers_email_string(receivers), content, url
rescue => e
Rails.logger.info("MessageTemplate::IssueAssigned.get_email_message_content [ERROR] #{e}")
return '', '', ''
end
end

View File

@ -23,4 +23,13 @@ class MessageTemplate::OrganizationJoined < MessageTemplate
Rails.logger.info("MessageTemplate::OrganizationJoined.get_message_content [ERROR] #{e}")
return '', '', ''
end
def self.get_email_message_content(receivers, organization)
content = email.gsub('{organization}', organization&.real_name)
url = notification_url.gsub('{login}', organization&.login)
return receivers_email_string(receivers), content, url
rescue => e
Rails.logger.info("MessageTemplate::OrganizationJoined.get_email_message_content [ERROR] #{e}")
return '', '', ''
end
end

View File

@ -23,4 +23,14 @@ class MessageTemplate::OrganizationLeft < MessageTemplate
Rails.logger.info("MessageTemplate::OrganizationLeft.get_message_content [ERROR] #{e}")
return '', '', ''
end
def self.get_email_message_content(receivers, organization)
content = email.gsub('{organization}', organization&.real_name)
url = notification_url.gsub('{login}', organization&.login)
return receivers_email_string(receivers), content, url
rescue => e
Rails.logger.info("MessageTemplate::OrganizationLeft.get_email_message_content [ERROR] #{e}")
return '', '', ''
end
end

View File

@ -23,4 +23,13 @@ class MessageTemplate::OrganizationRole < MessageTemplate
Rails.logger.info("MessageTemplate::OrganizationRole.get_message_content [ERROR] #{e}")
return '', '', ''
end
def self.get_email_message_content(receivers, organization, role)
content = email.gsub('{organization}', organization&.real_name).gsub('{role}', role)
url = notification_url.gsub('{login}', organization&.login)
return receivers_email_string(receivers), content, url
rescue => e
Rails.logger.info("MessageTemplate::OrganizationRole.get_email_message_content [ERROR] #{e}")
return '', '', ''
end
end

View File

@ -27,4 +27,17 @@ class MessageTemplate::ProjectIssue < MessageTemplate
Rails.logger.info("MessageTemplate::ProjectIssue.get_message_content [ERROR] #{e}")
return '', '', ''
end
def self.get_email_message_content(managers, followers, operator, issue)
project = issue&.project
owner = project&.owner
receivers = managers + followers
content = email.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name).gsub('{title}', issue&.subject)
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s)
return receivers_email_string(receivers), content, url
rescue => e
Rails.logger.info("MessageTemplate::ProjectIssue.get_email_message_content [ERROR] #{e}")
return '', '', ''
end
end

View File

@ -23,4 +23,12 @@ class MessageTemplate::ProjectJoined < MessageTemplate
Rails.logger.info("MessageTemplate::ProjectJoined.get_message_content [ERROR] #{e}")
return '', '', ''
end
def self.get_email_message_content(receivers, project)
content = email.gsub('{repository}', project&.name)
url = notification_url.gsub('{owner}', project&.owner&.login).gsub('{identifier}', project&.identifier)
rescue => e
Rails.logger.info("MessageTemplate::ProjectJoined.get_email_message_content [ERROR] #{e}")
return '', '', ''
end
end

View File

@ -23,4 +23,14 @@ class MessageTemplate::ProjectLeft < MessageTemplate
Rails.logger.info("MessageTemplate::ProjectLeft.get_message_content [ERROR] #{e}")
return '', '', ''
end
def self.get_email_message_content(receivers, project)
content = email.gsub('{repository}', project&.name)
url = notification_url.gsub('{owner}', project&.owner&.login).gsub('{identifier}', project&.identifier)
return receivers_email_string(receivers), content, url
rescue => e
Rails.logger.info("MessageTemplate::ProjectLeft.get_email_message_content [ERROR] #{e}")
return '', '', ''
end
end

View File

@ -23,4 +23,13 @@ class MessageTemplate::ProjectMemberJoined < MessageTemplate
Rails.logger.info("MessageTemplate::ProjectMemberJoined.get_message_content [ERROR] #{e}")
return '', '', ''
end
def self.get_email_message_content(receivers, user, project)
content = email.gsub('{nickname}', user&.real_name).gsub('{nickname2}', project&.owner&.real_name).gsub('{repository}', project&.name)
url = notification_url.gsub('{owner}', project&.owner&.login).gsub('{identifier}', project&.identifier)
return receivers_email_string(receivers), content, url
rescue => e
Rails.logger.info("MessageTemplate::ProjectMemberJoined.get_email_message_content [ERROR] #{e}")
return '', '', ''
end
end

View File

@ -23,4 +23,13 @@ class MessageTemplate::ProjectMemberLeft < MessageTemplate
Rails.logger.info("MessageTemplate::ProjectMemberLeft.get_message_content [ERROR] #{e}")
return '', '', ''
end
def self.get_email_message_content(receivers, user, project)
content = email.gsub('{nickname1}', user&.real_name).gsub('{nickname2}', project&.owner&.real_name).gsub("{repository}", project&.name)
url = notification_url.gsub('{owner}', project&.owner&.login).gsub('{identifier}', project&.identifier)
return receivers_email_string(receivers), content, url
rescue => e
Rails.logger.info("MessageTemplate::ProjectMemberLeft.get_email_message_content [ERROR] #{e}")
return '', '', ''
end
end

View File

@ -27,4 +27,17 @@ class MessageTemplate::ProjectPullRequest < MessageTemplate
Rails.logger.info("MessageTemplate::ProjectPullRequest.get_message_content [ERROR] #{e}")
return '', '', ''
end
def self.get_email_message_content(managers, followers, operator, pull_request)
project = pull_request&.project
owner = project&.owner
receivers = managers + followers
content = email.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name).gsub('{title}', pull_request&.title)
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', pull_request&.id.to_s)
return receivers_email_string(receivers), content, url
rescue => e
Rails.logger.info("MessageTemplate::ProjectPullRequest.get_email_message_content [ERROR] #{e}")
return '', '', ''
end
end

View File

@ -23,4 +23,13 @@ class MessageTemplate::ProjectRole < MessageTemplate
Rails.logger.info("MessageTemplate::ProjectRole.get_message_content [ERROR] #{e}")
return '', '', ''
end
def self.get_email_message_content(receivers, project, role)
content = email.gsub('{repository}', project&.name).gsub('{role}', role)
url = notification_url.gsub('{owner}', project&.owner&.login).gsub('{identifier}', project&.identifier)
return receivers_email_string(receivers), content, url
rescue => e
Rails.logger.info("MessageTemplate::ProjectRole.get_email_message_content [ERROR] #{e}")
return '', '', ''
end
end

View File

@ -138,4 +138,128 @@ class MessageTemplate::ProjectSettingChanged < MessageTemplate
Rails.logger.info("MessageTemplate::ProjectSettingChanged.get_message_content [ERROR] #{e}")
return '', '', ''
end
def self.get_email_message_content(receivers, operator, project, change_params)
return '', '', '' if change_params.blank?
owner = project&.owner
content = email.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name)
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier)
change_count = change_params.keys.size
# 项目名称更改
if change_params[:name].present?
if change_count > 1
content.sub!('{ifname}', '<br/>')
else
content.sub!('{ifname}', '')
end
content.sub!('{endname}', '')
content.gsub!('{name}', change_params[:name][1])
else
content.gsub!(/({ifname})(.*)({endname})/, '')
end
# 项目简介更改
if change_params[:description].present?
if change_params[:description][1].blank?
if change_count > 1
content.gsub!(/({ifdescription})(.*)({enddescription})/, '<br/>删除了项目简介')
else
content.gsub!(/({ifdescription})(.*)({enddescription})/, '删除了项目简介')
end
else
if change_count > 1
content.sub!('{ifdescription}', '<br/>')
else
content.sub!('{ifdescription}', '')
end
content.sub!('{enddescription}', '')
content.gsub!('{description}', change_params[:description][1])
end
else
content.gsub!(/({ifdescription})(.*)({enddescription})/, '')
end
# 项目类别更改
if change_params[:project_category_id].present?
category = ProjectCategory.find_by_id(change_params[:project_category_id][1])
if category.present?
if change_count > 1
content.sub!('{ifcategory}', '<br/>')
else
content.sub!('{ifcategory}', '')
end
content.sub!('{endcategory}', '')
content.gsub!('{category}', category&.name)
else
if change_count > 1
content.gsub!(/({ifcategory})(.*)({endcategory})/, '<br/>删除了项目类别')
else
content.gsub!(/({ifcategory})(.*)({endcategory})/, '删除了项目类别')
end
end
else
content.gsub!(/({ifcategory})(.*)({endcategory})/, '')
end
# 项目语言更改
if change_params[:project_language_id].present?
language = ProjectLanguage.find_by_id(change_params[:project_language_id][1])
if language.present?
if change_count > 1
content.sub!('{iflanguage}', '<br/>')
else
content.sub!('{iflanguage}', '')
end
content.sub!('{endlanguage}', '')
content.gsub!('{language}', language&.name)
else
if change_count > 1
content.gsub!(/({iflanguage})(.*)({endlanguage})/, '<br/>删除了项目语言')
else
content.gsub!(/({iflanguage})(.*)({endlanguage})/, '删除了项目语言')
end
end
else
content.gsub!(/({iflanguage})(.*)({endlanguage})/, '')
end
# 项目公私有更改
if change_params[:is_public].present?
permission = change_params[:is_public][1] ? '公有' : '私有'
if change_count > 1
content.sub!('{ifpermission}', '<br/>')
else
content.sub!('{ifpermission}', '')
end
content.sub!('{endpermission}', '')
content.gsub!('{permission}', permission)
else
content.gsub!(/({ifpermission})(.*)({endpermission})/, '')
end
# 项目导航更改
if change_params[:navbar].present?
unit_types = project.project_units.order(unit_type: :asc).pluck(:unit_type)
unit_types.delete('code')
unit_types.unshift('代码库')
unit_types.unshift('主页')
unit_types.append('动态')
navbar = unit_types.join('')
navbar.gsub!('issues', '易修')
navbar.gsub!('pulls', '合并请求')
navbar.gsub!('wiki', 'Wiki')
navbar.gsub!('devops', '工作流')
navbar.gsub!('versions', '里程碑')
navbar.gsub!('resources', '资源库')
if change_count > 1
content.sub!('{ifnavbar}', '<br/>')
else
content.sub!('{ifnavbar}', '')
end
content.sub!('{endnavbar}', '')
content.gsub!('{navbar}', navbar)
else
content.gsub!(/({ifnavbar})(.*)({endnavbar})/, '')
end
return receivers_email_string(receivers), content, url
rescue => e
Rails.logger.info("MessageTemplate::ProjectSettingChanged.get_email_message_content [ERROR] #{e}")
return '', '', ''
end
end

View File

@ -25,4 +25,15 @@ class MessageTemplate::PullRequestAssigned < MessageTemplate
Rails.logger.info("MessageTemplate::PullRequestAssigned.get_message_content [ERROR] #{e}")
return '', '', ''
end
def self.get_email_message_content(receivers, operator, pull_request)
project = pull_request&.project
owner = project&.owner
content = email.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name).gsub('{title}', pull_request&.title)
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', pull_request&.id.to_s)
return receivers_email_string(receivers), content, url
rescue => e
Rails.logger.info("MessageTemplate::PullRequestAssigned.get_email_message_content [ERROR] #{e}")
return '', '', ''
end
end

View File

@ -48,7 +48,11 @@ class Notice::Read::ClientService < ApplicationService
end
end
#private
def platform
Notice.notice_config[:platform]
end
private
def conn
@client ||= begin
Faraday.new(url: domain) do |req|
@ -69,12 +73,8 @@ class Notice::Read::ClientService < ApplicationService
Notice.notice_config[:read_domain]
end
def platform
Notice.notice_config[:platform]
end
def api_url
[domain, base_url, "/#{platform}"].join('')
[domain, base_url].join('')
end
def full_url(api_rest, action='post')

View File

@ -20,6 +20,6 @@ class Notice::Read::CountService < Notice::Read::ClientService
end
def url
"/count".freeze
"/notification/#{platform}/count".freeze
end
end

View File

@ -27,6 +27,6 @@ class Notice::Read::ListService < Notice::Read::ClientService
end
def url
"/list".freeze
"/notification/#{platform}/list".freeze
end
end

View File

@ -9,7 +9,7 @@ class Notice::Write::ChangeStatusService < Notice::Write::ClientService
end
def call
result = put("", request_params)
result = put(url, request_params)
response = render_response(result)
end
@ -28,4 +28,8 @@ class Notice::Write::ChangeStatusService < Notice::Write::ClientService
}.stringify_keys)
end
def url
"/notification/#{platform}".freeze
end
end

View File

@ -48,7 +48,11 @@ class Notice::Write::ClientService < ApplicationService
end
end
#private
def platform
Notice.notice_config[:platform]
end
private
def conn
@client ||= begin
Faraday.new(url: domain) do |req|
@ -69,12 +73,8 @@ class Notice::Write::ClientService < ApplicationService
Notice.notice_config[:write_domain]
end
def platform
Notice.notice_config[:platform]
end
def api_url
[domain, base_url, "/#{platform}"].join('')
[domain, base_url].join('')
end
def full_url(api_rest, action='post')

View File

@ -13,7 +13,7 @@ class Notice::Write::CreateService < Notice::Write::ClientService
def call
return nil if request_receivers.blank?
result = post("", request_params)
result = post(url, request_params)
response = render_response(result)
end
@ -35,4 +35,8 @@ class Notice::Write::CreateService < Notice::Write::ClientService
}.stringify_keys)
end
def url
"/notification/#{platform}".freeze
end
end

View File

@ -8,7 +8,7 @@ class Notice::Write::DeleteService < Notice::Write::ClientService
end
def call
result = delete("", request_params)
result = delete(url, request_params)
response = render_response(result)
end
@ -26,4 +26,8 @@ class Notice::Write::DeleteService < Notice::Write::ClientService
}.stringify_keys)
end
def url
"/notification/#{platform}".freeze
end
end

View File

@ -0,0 +1,36 @@
class Notice::Write::EmailCreateService < Notice::Write::ClientService
attr_accessor :receivers, :sender, :content, :subject
def initialize(receivers, content, subject, sender=-1)
@receivers = receivers
@sender = sender
@content = content
@subject = subject
end
def call
return nil if request_receivers.blank?
result = post(url, request_params)
response = render_response(result)
end
private
def request_receivers
receivers.is_a?(Array) ? receivers.join(",") : receivers
end
def request_params
Hash.new.merge(data: {
emails: request_receivers,
sender: sender,
content: content,
subject: subject
}.stringify_keys)
end
def url
"/email/#{platform}".freeze
end
end