Class: Nuntius::DeliverCampaignService
- Inherits:
-
ApplicationService
- Object
- Servitium::Service
- ApplicationService
- Nuntius::DeliverCampaignService
- Defined in:
- app/services/nuntius/deliver_campaign_service.rb
Instance Method Summary collapse
- #deliver ⇒ Object
- #new_message(subscriber, assigns = {}) ⇒ Object
- #perform ⇒ Object
- #translation_scope ⇒ Object
Instance Method Details
#deliver ⇒ Object
17 18 19 20 21 22 |
# File 'app/services/nuntius/deliver_campaign_service.rb', line 17 def deliver transporter = BaseTransport.class_from_name(campaign.transport).new campaign.list.subscribers.subscribed.each do |subscriber| transporter.deliver((subscriber)) end end |
#new_message(subscriber, assigns = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/services/nuntius/deliver_campaign_service.rb', line 24 def (subscriber, assigns = {}) assigns["campaign"] = context.campaign assigns["subscriber"] = subscriber if subscriber.nuntiable name = Nuntius::BaseMessenger.liquid_variable_name_for(subscriber.nuntiable) assigns[name] = subscriber.nuntiable end = Nuntius::Message.new(transport: campaign.transport, campaign: campaign, nuntiable: subscriber.nuntiable, metadata: campaign.) locale = nil if subscriber.nuntiable locale_proc = Nuntius::BaseMessenger.messenger_for_obj(subscriber.nuntiable).locale locale = instance_exec(subscriber.nuntiable, &locale_proc) if locale_proc end .from = render(:from, assigns, locale) .to = case campaign.transport when "mail" subscriber.email when "sms" subscriber.phone_number when "voice" subscriber.phone_number end .subject = render(:subject, assigns, locale) .html = render(:html, assigns, locale, layout: campaign.layout&.data) end |
#perform ⇒ Object
12 13 14 15 |
# File 'app/services/nuntius/deliver_campaign_service.rb', line 12 def perform deliver # campaign.sent! end |
#translation_scope ⇒ Object
55 56 57 58 59 |
# File 'app/services/nuntius/deliver_campaign_service.rb', line 55 def translation_scope scope = %w[nuntius] scope << campaign.layout.name.underscore.tr(" ", "_") if layout scope.join(".") end |