Class: Esendex::Batch

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/xednese/batch.rb

Constant Summary collapse

PAGE_COUNT =
25

Instance Method Summary collapse

Constructor Details

#initialize(credentials, response) ⇒ Batch

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Batch.

See Also:



7
8
9
10
# File 'lib/xednese/batch.rb', line 7

def initialize(credentials, response)
  @credentials = credentials
  @response = response
end

Instance Method Details

#cancel!Object



48
49
50
# File 'lib/xednese/batch.rb', line 48

def cancel!
  Client.delete(@credentials, "v1.1/messagebatches/#{id}/schedule")
end

#messagesEnumerable<Responses::MessageHeader>

Returns an Enumerable that iterates over all messages in the batch. Requests are made for fixed size pages when required.

Returns:

  • (Enumerable<Responses::MessageHeader>)

    an Enumerable that iterates over all messages in the batch. Requests are made for fixed size pages when required.



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/xednese/batch.rb', line 55

def messages
  Seq::Paged.new do |page|
    params = {
      startIndex: PAGE_COUNT * page,
      count: PAGE_COUNT
    }

    Client.get(@credentials, "v1.0/messagebatches/#{id}/messages", params) do |status, data|
      Responses::MessageHeaders.deserialise(data).message_headers
    end
  end
end

#nameObject



36
37
38
# File 'lib/xednese/batch.rb', line 36

def name
  @name || @response.name
end

#name=(value) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/xednese/batch.rb', line 40

def name=(value)
  request = Requests::Batch.new(name: value)

  Client.put(@credentials, "v1.1/messagebatches/#{id}", request) do |status, data|
    @name = value
  end
end

#statusObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/xednese/batch.rb', line 17

def status
  s = @response.status

  [:acknowledged,
   :authorisation_failed,
   :connecting,
   :delivered,
   :failed,
   :partially_delivered,
   :rejected,
   :scheduled,
   :sent,
   :submitted,
   :validity_period_expired,
   :cancelled].find do |type|
    s.send(type) == 1
  end
end