class GoogleAdsSavon::SOAP::Fault

GoogleAdsSavon::SOAP::Fault

Represents a SOAP fault. Contains the original HTTPI::Response.

Attributes

http[RW]

Accessor for the HTTPI::Response.

Public Class Methods

new(http) click to toggle source

Expects an HTTPI::Response.

# File lib/ads_savon/soap/fault.rb, line 13
def initialize(http)
  self.http = http
end

Public Instance Methods

present?() click to toggle source

Returns whether a SOAP fault is present.

# File lib/ads_savon/soap/fault.rb, line 21
def present?
  @present ||= http.body.include?("Fault>") && (soap1_fault? || soap2_fault?)
end
to_hash() click to toggle source

Returns the SOAP response body as a Hash.

# File lib/ads_savon/soap/fault.rb, line 32
def to_hash
  @hash ||= nori.parse(http.body)[:envelope][:body]
end
to_s() click to toggle source

Returns the SOAP fault message.

# File lib/ads_savon/soap/fault.rb, line 26
def to_s
  return "" unless present?
  @message ||= message_by_version to_hash[:fault]
end

Private Instance Methods

message_by_version(fault) click to toggle source

Returns the SOAP fault message by version.

# File lib/ads_savon/soap/fault.rb, line 49
def message_by_version(fault)
  if fault[:faultcode]
    "(#{fault[:faultcode]}) #{fault[:faultstring]}"
  elsif fault[:code]
    "(#{fault[:code][:value]}) #{fault[:reason][:text]}"
  end
end
nori() click to toggle source
# File lib/ads_savon/soap/fault.rb, line 57
def nori
  return @nori if @nori

  nori_options = {
    :strip_namespaces      => true,
    :convert_tags_to       => lambda { |tag| tag.snakecase.to_sym },
    :empty_tag_value       => "",
    :advanced_typecasting  => false
  }

  non_nil_nori_options = nori_options.reject { |_, value| value.nil? }
  @nori = Nori.new(non_nil_nori_options)
end
soap1_fault?() click to toggle source

Returns whether the response contains a SOAP 1.1 fault.

# File lib/ads_savon/soap/fault.rb, line 39
def soap1_fault?
  http.body.include?("faultcode>") && http.body.include?("faultstring>")
end
soap2_fault?() click to toggle source

Returns whether the response contains a SOAP 1.2 fault.

# File lib/ads_savon/soap/fault.rb, line 44
def soap2_fault?
  http.body.include?("Code>") && http.body.include?("Reason>")
end