Class: Apostle::Queue
- Inherits:
-
Object
- Object
- Apostle::Queue
- Defined in:
- lib/apostle/queue.rb
Instance Attribute Summary collapse
-
#emails ⇒ Object
Returns the value of attribute emails.
-
#results ⇒ Object
Returns the value of attribute results.
Instance Method Summary collapse
- #<<(email) ⇒ Object
- #add(email) ⇒ Object
- #clear ⇒ Object
- #deliver ⇒ Object
- #deliver! ⇒ Object
- #flush ⇒ Object
-
#initialize ⇒ Queue
constructor
A new instance of Queue.
- #size ⇒ Object
Constructor Details
#initialize ⇒ Queue
Returns a new instance of Queue.
9 10 11 |
# File 'lib/apostle/queue.rb', line 9 def initialize @emails = [] end |
Instance Attribute Details
#emails ⇒ Object
Returns the value of attribute emails.
7 8 9 |
# File 'lib/apostle/queue.rb', line 7 def emails @emails end |
#results ⇒ Object
Returns the value of attribute results.
7 8 9 |
# File 'lib/apostle/queue.rb', line 7 def results @results end |
Instance Method Details
#<<(email) ⇒ Object
13 14 15 |
# File 'lib/apostle/queue.rb', line 13 def <<(email) add(email) end |
#add(email) ⇒ Object
17 18 19 |
# File 'lib/apostle/queue.rb', line 17 def add(email) @emails << email end |
#clear ⇒ Object
25 26 27 28 |
# File 'lib/apostle/queue.rb', line 25 def clear emails = [] results = nil end |
#deliver ⇒ Object
34 35 36 37 38 |
# File 'lib/apostle/queue.rb', line 34 def deliver deliver! rescue DeliveryError false end |
#deliver! ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/apostle/queue.rb', line 40 def deliver! return true unless Apostle.deliver # Validate the minimum requirement of a recipient and template unless Apostle.domain_key raise DeliveryError, "No Apostle Domain Key has been defined. Preferably this should be in your environment, as ENV['APOSTLE_DOMAIN_KEY']. If you need to configure this manually, you can call Apostle.configure. Apostle.configure do |config| config.domain_key = 'Your domain key' end" end raise DeliveryError, "Mail queue is empty" if emails.size == 0 payload, @results = process_emails if @results[:invalid].size > 0 raise DeliveryError, "Invalid emails: #{@results[:invalid].size}" end # Deliver the payload response = deliver_payload(payload) true end |
#flush ⇒ Object
30 31 32 |
# File 'lib/apostle/queue.rb', line 30 def flush deliver && clear end |
#size ⇒ Object
21 22 23 |
# File 'lib/apostle/queue.rb', line 21 def size emails.size end |