lib/mblox/sms_response.rb in mblox-0.2.5 vs lib/mblox/sms_response.rb in mblox-0.2.6

- old
+ new

@@ -1,15 +1,14 @@ -require 'active_model/serialization' -require 'active_model/serializers/xml.rb' - require 'active_model/callbacks' require 'active_model/validator' require 'active_model/naming' require 'active_model/translation' require 'active_model/validations' require 'active_model/errors' +require 'mblox/from_xml' + module Mblox class SmsResponse class Result include ActiveModel::Validations validates_presence_of :text, :code, :message => "%{attribute} cannot be blank" @@ -32,11 +31,11 @@ UNROUTABLE = new(10, UNROUTABLE_TEXT) end attr_reader :request, :result, :subscriber_result def initialize(xml) - data = Hash.from_xml(xml) - data = data['NotificationRequestResult'] + data = Mblox.from_xml(xml)['NotificationRequestResult'] + raise MissingExpectedXmlContentError, "Xml should have contained a 'NotificationRequestResult' node, but was #{xml}" if data.blank? header = data['NotificationResultHeader'] raise MissingExpectedXmlContentError, "Xml should have contained a 'NotificationRequestResult' -> 'NotificationResultHeader' node, but was #{xml}" if header.blank? @request = Result.new(header['RequestResultCode'], header['RequestResultText']) @request = nil unless @request.valid?