class Mblox::SmsResponse
Constants
- ATTRIBUTES
Public Class Methods
new(args)
click to toggle source
# File lib/mblox/sms_response.rb, line 45 def initialize args args = args.symbolize_keys ATTRIBUTES.each do |attr| __send__("#{attr}=", args[attr]) args.delete(attr) end raise ::ArgumentError, "Unrecognized attributes: #{args.inspect}" unless args.empty? wrong_type_fields = ATTRIBUTES.reject { |attr| __send__(attr).nil? || __send__(attr).is_a?(self.class::Result) } if 1 == wrong_type_fields.count raise ValidationError, "#{wrong_type_fields.first} must be of type Mblox::SmsResponse::Result" elsif wrong_type_fields.count > 1 raise ValidationError, "The following fields must be of type Mblox::SmsResponse::Result: #{wrong_type_fields.join(', ')}" end missing_fields = [:request, :result].reject { |attr| __send__(attr) } missing_fields << :subscriber_result if result && result.ok? && subscriber_result.nil? if 1 == missing_fields.count raise ValidationError, "#{missing_fields.first} cannot be blank" elsif missing_fields.count > 1 raise ValidationError, "The following fields cannot be blank: #{missing_fields.join(', ')}" end end
Private Class Methods
from_xml(xml)
click to toggle source
# File lib/mblox/sms_response.rb, line 81 def from_xml(xml) args = {} data = Mblox.from_xml(xml).xpath '//NotificationRequestResult' raise MissingExpectedXmlContentError, "Xml should have contained a 'NotificationRequestResult' node, but was #{xml}" if data.blank? header = data.xpath '//NotificationResultHeader' raise MissingExpectedXmlContentError, "Xml should have contained a 'NotificationRequestResult' -> 'NotificationResultHeader' node, but was #{xml}" if header.blank? args[:request] = Result.from_xml(header, :RequestResult) args[:request] = nil unless args[:request].valid? result_list = data.xpath '//NotificationResultList' raise MissingExpectedXmlContentError, "Xml should have contained a 'NotificationRequestResult' -> 'NotificationResultList' node, but was #{xml}" if result_list.blank? result_list = result_list.xpath '//NotificationResult' raise MissingExpectedXmlContentError, "Xml should have contained a 'NotificationRequestResult' -> 'NotificationResultList' -> 'NotificationResult' node, but was #{xml}" if result_list.blank? args[:result] = Result.from_xml(result_list, :NotificationResult) args[:result] = nil unless args[:result].valid? if args[:result].ok? result_list = result_list.xpath '//SubscriberResult' raise MissingExpectedXmlContentError, "Xml should have contained a 'NotificationRequestResult' -> 'NotificationResultList' -> 'NotificationResult' -> 'SubscriberResult' node, but was #{xml}" if result_list.blank? args[:subscriber_result] = Result.from_xml(result_list, :SubscriberResult) args[:subscriber_result] = nil unless args[:subscriber_result].valid? end new(args) end
Public Instance Methods
ok?()
click to toggle source
# File lib/mblox/sms_response.rb, line 69 def ok? @request.ok? && @result.ok? && @subscriber_result.ok? end
unroutable?()
click to toggle source
# File lib/mblox/sms_response.rb, line 73 def unroutable? @request.ok? && @result.ok? && Result::UNROUTABLE == @subscriber_result end