class Adyen::API::XMLQuerier

A simple wrapper around the raw response body returned by Adyen. It abstracts away the differences between REXML and Nokogiri, ensuring that this library will always work.

At load time, it will first check if Nokogiri is available, otherwise REXML is used. This means that if you want to use Nokogiri and have it installed as a gem, you will have to make sure rubygems is loaded and the gem has been activated. Or assign the backend to use.

Constants

NS

The namespaces used by Adyen.

Attributes

backend[R]

Public Class Methods

default_backend() click to toggle source

@return A backend to handle XML parsing.

   # File lib/adyen/api/xml_querier.rb
63 def self.default_backend
64   @default_backend ||= begin
65     NokogiriBackend.new
66   rescue LoadError
67     REXMLBackend.new
68   end
69 end
html(data, backend = nil) click to toggle source

Creates an XML querier for an HTML document

   # File lib/adyen/api/xml_querier.rb
78 def self.html(data, backend = nil)
79   backend ||= default_backend
80   self.new(backend.document_for_html(string_from(data)), backend)
81 end
new(node, backend) click to toggle source

@param [Nokogiri::XML::NodeSet] data The XML data to wrap.

   # File lib/adyen/api/xml_querier.rb
96 def initialize(node, backend)
97   @node, @backend = node, backend
98 end
string_from(data) click to toggle source
   # File lib/adyen/api/xml_querier.rb
83 def self.string_from(data)
84   if data.is_a?(String)
85     data
86   elsif data.responds_to?(:body)
87     data.body.to_s
88   else 
89     data.to_s
90   end
91 end
xml(data, backend = nil) click to toggle source

Creates an XML querier for an XML document

   # File lib/adyen/api/xml_querier.rb
72 def self.xml(data, backend = nil)
73   backend ||= default_backend
74   self.new(backend.document_for_xml(string_from(data)), backend)
75 end

Public Instance Methods

children() click to toggle source

@return [Array, Nokogiri::XML::NodeSet] The children of this node.

    # File lib/adyen/api/xml_querier.rb
116 def children
117   @node.first.children
118 end
empty?() click to toggle source

@return [Boolean] Returns whether or not this node is empty.

    # File lib/adyen/api/xml_querier.rb
121 def empty?
122   @node.empty?
123 end
map(&block) click to toggle source

@yield [XMLQuerier] A member of this node set, ready to be queried. @return [Array] The list of nodes wrapped in XMLQuerier instances.

    # File lib/adyen/api/xml_querier.rb
132 def map(&block)
133   @node.map { |n| self.class.new(n, backend) }.map(&block)
134 end
text(query) click to toggle source

@param [String] query The xpath query to perform. @return [String] The contents of the text node indicated by the given query.

    # File lib/adyen/api/xml_querier.rb
111 def text(query)
112   xpath("#{query}/text()").to_s.strip
113 end
to_s() click to toggle source

@return [String] A string representation of this node.

    # File lib/adyen/api/xml_querier.rb
126 def to_s
127   backend.stringify_nodeset(@node)
128 end
xpath(query) { |result| ... } click to toggle source

@param [String] query The xpath query to perform. @yield [XMLQuerier] A new XMLQuerier scoped to the given query. @return [XMLQuerier] A new XMLQuerier scoped to the given query. Or, if a block is given,

the result of calling the block.
    # File lib/adyen/api/xml_querier.rb
104 def xpath(query)
105   result = self.class.new(backend.perform_xpath(query, @node), backend)
106   block_given? ? yield(result) : result
107 end