Class: Emailable::Batch
- Inherits:
-
Object
- Object
- Emailable::Batch
- Defined in:
- lib/emailable/batch.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
Instance Method Summary collapse
- #complete? ⇒ Boolean
-
#initialize(id_or_emails) ⇒ Batch
constructor
A new instance of Batch.
- #inspect ⇒ Object
- #status(parameters = {}) ⇒ Object
- #verify(parameters = {}) ⇒ Object
Constructor Details
#initialize(id_or_emails) ⇒ Batch
Returns a new instance of Batch.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/emailable/batch.rb', line 5 def initialize(id_or_emails) if id_or_emails.is_a?(Array) @id = nil @emails = id_or_emails elsif id_or_emails.is_a?(String) @id = id_or_emails @emails = nil else raise ArgumentError, 'expected an array of emails or batch id' end @client = Emailable::Client.new @status = nil end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/emailable/batch.rb', line 3 def id @id end |
Instance Method Details
#complete? ⇒ Boolean
41 42 43 |
# File 'lib/emailable/batch.rb', line 41 def complete? status.complete? end |
#inspect ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/emailable/batch.rb', line 45 def inspect ivars = instance_variables.map do |e| [e.to_s.delete('@'), instance_variable_get(e)] end.to_h "#<#{self.class}:0x#{(object_id << 1).to_s(16)}> JSON: " + JSON.pretty_generate(ivars) end |
#status(parameters = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/emailable/batch.rb', line 29 def status(parameters = {}) return nil unless @id return @status if @status parameters[:id] = @id response = @client.request(:get, 'batch', parameters) bs = BatchStatus.new(response.body) @status = bs if bs.complete? bs end |
#verify(parameters = {}) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/emailable/batch.rb', line 20 def verify(parameters = {}) return @id unless @id.nil? parameters[:emails] = @emails.join(',') response = @client.request(:post, 'batch', parameters) @id = response.body['id'] end |