Class: Nuntius::BaseTransport

Inherits:
Object
  • Object
show all
Defined in:
app/transports/nuntius/base_transport.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.class_from_name(name) ⇒ Object



32
33
34
# File 'app/transports/nuntius/base_transport.rb', line 32

def self.class_from_name(name)
  Nuntius.const_get("#{name}_transport".camelize)
end

Instance Method Details

#deliver(message) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/transports/nuntius/base_transport.rb', line 9

def deliver(message)
  priority = 1
  wait_time = 0
  message.update(transport: kind.to_s) if message.transport.blank?
  while (providers_for_priority = providers(priority)).present?
    time_out = 0
    providers_for_priority.each do |hash|
      message.update(provider: hash[:provider].to_s) if message.provider.blank?

      Nuntius::TransportDeliveryJob.set(wait: !Rails.env.development? && wait_time).perform_later(hash[:provider].to_s, message)
      time_out += hash[:timeout].seconds if hash[:timeout].positive?
    end
    wait_time += time_out
    priority += 1
  end
end

#kindObject



5
6
7
# File 'app/transports/nuntius/base_transport.rb', line 5

def kind
  self.class.name.demodulize.gsub(/Transport$/, "").underscore.to_sym
end

#providers(priority = nil) ⇒ Object



26
27
28
29
30
# File 'app/transports/nuntius/base_transport.rb', line 26

def providers(priority = nil)
  results = Nuntius.config.providers[kind].to_a
  results = results.select { |provider| provider[:priority] == priority } if priority
  results
end