Class: BlazeVerify::Batch
- Inherits:
-
Object
- Object
- BlazeVerify::Batch
- Defined in:
- lib/blazeverify/batch.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
Instance Method Summary collapse
- #complete? ⇒ Boolean
-
#initialize(id_or_emails, callback: nil) ⇒ Batch
constructor
A new instance of Batch.
- #status ⇒ Object
- #verify ⇒ Object
Constructor Details
#initialize(id_or_emails, callback: nil) ⇒ Batch
Returns a new instance of Batch.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/blazeverify/batch.rb', line 5 def initialize(id_or_emails, callback: nil) if id_or_emails.is_a?(Array) @emails = id_or_emails @callback = callback elsif id_or_emails.is_a?(String) @id = id_or_emails else raise ArgumentError, 'expected an array of emails or batch id' end @client = BlazeVerify::Client.new end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/blazeverify/batch.rb', line 3 def id @id end |
Instance Method Details
#complete? ⇒ Boolean
38 39 40 |
# File 'lib/blazeverify/batch.rb', line 38 def complete? !status.complete? end |
#status ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/blazeverify/batch.rb', line 27 def status return nil unless @id return @status if @status response = @client.request(:get, 'batch', { id: @id }) bs = BatchStatus.new(response.body) @status = bs if bs.complete? bs end |
#verify ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/blazeverify/batch.rb', line 18 def verify return @id unless @id.nil? opts = { emails: @emails.join(','), url: @callback } response = @client.request(:post, 'batch', opts) @id = response.body['id'] end |