Class: Esendex::DispatcherResult

Inherits:
Object
  • Object
show all
Defined in:
lib/esendex/dispatcher_result.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(batch_id, messages) ⇒ DispatcherResult

Returns a new instance of DispatcherResult.



7
8
9
10
# File 'lib/esendex/dispatcher_result.rb', line 7

def initialize(batch_id, messages)
  @batch_id = batch_id
  @messages = messages
end

Instance Attribute Details

#batch_idObject (readonly)

Returns the value of attribute batch_id.



5
6
7
# File 'lib/esendex/dispatcher_result.rb', line 5

def batch_id
  @batch_id
end

#messagesObject (readonly)

Returns the value of attribute messages.



5
6
7
# File 'lib/esendex/dispatcher_result.rb', line 5

def messages
  @messages
end

Class Method Details

.from_xml(source) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/esendex/dispatcher_result.rb', line 12

def self.from_xml(source)
  doc = Nokogiri::XML source
  batch_id = doc.at_xpath('//api:messageheaders', 'api' => Esendex::API_NAMESPACE)['batchid']
  messages = doc.xpath('//api:messageheader', 'api' => Esendex::API_NAMESPACE).map do |header|
    { id: header['id'], uri: header['uri'] }
  end
  DispatcherResult.new batch_id, messages
end

Instance Method Details

#to_sObject



21
22
23
# File 'lib/esendex/dispatcher_result.rb', line 21

def to_s
  batch_id
end