Module: Astrotrain::Transports::Resque
- Defined in:
- lib/astrotrain/transports/resque.rb
Class Method Summary collapse
-
.create_hash(message, recipient) ⇒ Object
Creates a param hash for RestClient.
-
.deliver(message, url, options = {}) ⇒ Object
Public: Sends the message to the given address.
-
.process(url, message, recipient = nil, extra = nil) ⇒ Object
kept for backwards compatibility.
Class Method Details
.create_hash(message, recipient) ⇒ Object
Creates a param hash for RestClient.
message - Astrotrain::Message instance recipient - String email of the main recipient.
Returns a Hash for Resque.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/astrotrain/transports/resque.rb', line 44 def self.create_hash(, recipient) h = {:subject => .subject, :to => [], :from => [], :cc => [], :body => .body, :emails => .recipients.join(", "), :html => .html, :headers => .headers} [:to, :from, :cc].each do |key| .send(key).each_with_index do |addr, i| h[key] << {:name => addr.display_name, :address => addr.address} end end h end |
.deliver(message, url, options = {}) ⇒ Object
Public: Sends the message to the given address.
message - Astrotrain::Message instance url - String address of the Resque in this form:
"QUEUE/KLASS"
options - Optional Hash:
:recipient - String email of the main recipient
:extra - Hash to be merged with the payload
Returns a queued Resque::Job instance.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/astrotrain/transports/resque.rb', line 19 def self.deliver(, url, = {}) recipient = [:recipient] || .recipients.first uri = url.is_a?(Addressable::URI) ? url : Addressable::URI.parse(url) path = uri.path.dup path.sub! /^\//, '' queue, *job = path.split("/") if qu = uri.host job.unshift(queue) queue = qu end payload = create_hash(, recipient) if extra = [:extra] payload.update(extra) end ::Resque::Job.create(queue, job.join("/"), payload) end |
.process(url, message, recipient = nil, extra = nil) ⇒ Object
kept for backwards compatibility
57 58 59 |
# File 'lib/astrotrain/transports/resque.rb', line 57 def self.process(url, , recipient = nil, extra = nil) deliver(, url, :recipient => recipient, :extra => extra) end |