Sha256: e69f311a8637a403a016340eb648c98f9498df200b127b04b029c91b961bf2c5
Contents?: true
Size: 1.54 KB
Versions: 4
Compression:
Stored size: 1.54 KB
Contents
require 'mblox/from_xml' module Mblox class SmsReceipt attr_reader :batch_id, :subscriber_number, :timestamp, :msg_reference, :status, :reason 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 end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
mblox-0.2.9 | lib/mblox/sms_receipt.rb |
mblox-0.2.8 | lib/mblox/sms_receipt.rb |
mblox-0.2.7 | lib/mblox/sms_receipt.rb |
mblox-0.2.6 | lib/mblox/sms_receipt.rb |