Class: Mblox::SmsReceipt

Inherits:
Object
  • Object
show all
Defined in:
lib/mblox/sms_receipt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ SmsReceipt

Returns a new instance of SmsReceipt.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mblox/sms_receipt.rb', line 6

def initialize(xml)
  data = Mblox.from_xml(xml)['NotificationService']
  raise MissingExpectedXmlContentError, "Xml should have contained a 'NotificationService' node, but was #{xml}" if data.blank?

  data = data['NotificationList']
  raise MissingExpectedXmlContentError, "Xml should have contained a 'NotificationService' -> 'NotificationList' node, but was #{xml}" if data.blank?

  data = data['Notification']
  raise MissingExpectedXmlContentError, "Xml should have contained a 'NotificationService' -> 'NotificationList' -> 'Notification' node, but was #{xml}" if data.blank?

  @batch_id = data['BatchID'].to_i

  data = data['Subscriber']
  raise MissingExpectedXmlContentError, "Xml should have contained a 'NotificationService' -> 'NotificationList' -> 'Notification' -> 'Subscriber' node, but was #{xml}" if data.blank?

  @subscriber_number = data['SubscriberNumber']
  @subscriber_number = @subscriber_number[1..-1] if '1' == @subscriber_number[0]

  unless data['TimeStamp'].blank?
    @timestamp = begin
      Time.strptime("#{data['TimeStamp']}+0000", '%Y%m%d%H%M%z')
    rescue ArgumentError
      nil
    end
  end

  @timestamp = @timestamp.to_datetime if @timestamp

  @msg_reference = data['MsgReference']
  @status = data['Status']
  @reason = data['Reason'].blank? ? nil : data['Reason'].to_i
end

Instance Attribute Details

#batch_idObject (readonly)

Returns the value of attribute batch_id.



5
6
7
# File 'lib/mblox/sms_receipt.rb', line 5

def batch_id
  @batch_id
end

#msg_referenceObject (readonly)

Returns the value of attribute msg_reference.



5
6
7
# File 'lib/mblox/sms_receipt.rb', line 5

def msg_reference
  @msg_reference
end

#reasonObject (readonly)

Returns the value of attribute reason.



5
6
7
# File 'lib/mblox/sms_receipt.rb', line 5

def reason
  @reason
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/mblox/sms_receipt.rb', line 5

def status
  @status
end

#subscriber_numberObject (readonly)

Returns the value of attribute subscriber_number.



5
6
7
# File 'lib/mblox/sms_receipt.rb', line 5

def subscriber_number
  @subscriber_number
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



5
6
7
# File 'lib/mblox/sms_receipt.rb', line 5

def timestamp
  @timestamp
end