class GoogleAdsSavon::SOAP::Response
GoogleAdsSavon::SOAP::Response
¶ ↑
Represents the SOAP
response and contains the HTTP
response.
Attributes
Public Class Methods
Expects an HTTPI::Response
and handles errors.
# File lib/ads_savon/soap/response.rb, line 15 def initialize(config, response) self.config = config self.http = response raise_errors if config.raise_errors end
Public Instance Methods
Shortcut accessor for the SOAP
response body Hash.
# File lib/ads_savon/soap/response.rb, line 49 def [](key) body[key] end
Returns the SOAP
response body as a Hash.
# File lib/ads_savon/soap/response.rb, line 62 def body if !hash.has_key? :envelope raise GoogleAdsSavon::SOAP::InvalidResponseError, "Unable to parse response body '#{to_xml}'" end hash[:envelope][:body] end
Returns the SOAP
response header as a Hash.
# File lib/ads_savon/soap/response.rb, line 54 def header if !hash.has_key? :envelope raise GoogleAdsSavon::SOAP::InvalidResponseError, "Unable to parse response body '#{to_xml}'" end hash[:envelope][:header] end
Returns the GoogleAdsSavon::HTTP::Error
.
# File lib/ads_savon/soap/response.rb, line 44 def http_error @http_error ||= HTTP::Error.new http end
Returns whether there was an HTTP
error.
# File lib/ads_savon/soap/response.rb, line 39 def http_error? http_error.present? end
Returns the GoogleAdsSavon::SOAP::Fault
.
# File lib/ads_savon/soap/response.rb, line 34 def soap_fault @soap_fault ||= Fault.new http end
Returns whether there was a SOAP
fault.
# File lib/ads_savon/soap/response.rb, line 29 def soap_fault? soap_fault.present? end
Returns whether the request was successful.
# File lib/ads_savon/soap/response.rb, line 24 def success? !soap_fault? && !http_error? end
Traverses the SOAP
response body Hash for a given path
of Hash keys and returns the value as an Array. Defaults to return an empty Array in case the path does not exist or returns nil.
# File lib/ads_savon/soap/response.rb, line 74 def to_array(*path) result = path.inject body do |memo, key| return [] unless memo[key] memo[key] end result.kind_of?(Array) ? result.compact : [result].compact end
Returns an Array of Nokogiri::XML::Node
objects retrieved with the given path
. Automatically adds all of the document's namespaces unless a namespaces
hash is provided.
# File lib/ads_savon/soap/response.rb, line 100 def xpath(path, namespaces = nil) doc.xpath(path, namespaces || xml_namespaces) end
Private Instance Methods
# File lib/ads_savon/soap/response.rb, line 115 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
# File lib/ads_savon/soap/response.rb, line 106 def raise_errors raise soap_fault if soap_fault? raise http_error if http_error? end
# File lib/ads_savon/soap/response.rb, line 111 def xml_namespaces @xml_namespaces ||= doc.collect_namespaces end