module EPPClient::XML

This handles all the XML I/O

Attributes

msgQ_count[R]
msgQ_id[R]
recv_xml[R]
sent_xml[R]
trID[R]

Public Instance Methods

builder(opts = {}) { |xml| ... } click to toggle source

creates a Builder::XmlMarkup object, mostly only used by command

# File lib/epp-client/xml.rb, line 33
def builder(opts = {})
  raw_builder(opts) do |xml|
    xml.instruct! :xml, :version => '1.0', :encoding => 'UTF-8'
    xml.epp('xmlns' => EPPClient::SCHEMAS_URL['epp'], 'xmlns:epp' => EPPClient::SCHEMAS_URL['epp']) do
      yield xml
    end
  end
end
command(*args) { |xml| ... } click to toggle source

Creates the xml for the command.

You can either pass a block to it, in that case, it's the command body, or a series of procs, the first one being the commands, the other ones being the extensions.

command do |xml|
    xml.logout
end

or

command(lambda do |xml|
    xml.logout
  end, lambda do |xml|
    xml.extension
  end)
# File lib/epp-client/xml.rb, line 114
def command(*args, &_block)
  builder do |xml|
    xml.command do
      if block_given?
        yield xml
      else
        command = args.shift
        command.call(xml)
        args.each do |ext|
          xml.extension do
            ext.call(xml)
          end
        end
      end
      xml.clTRID(clTRID)
    end
  end
end
extension() { |xml| ... } click to toggle source

Wraps the content in an epp:extension.

# File lib/epp-client/xml.rb, line 134
def extension
  raw_builder do |xml|
    xml.extension do
      yield(xml)
    end
  end
end
get_result(args) click to toggle source

Takes a xml response and checks that the result is in the right range of results, that is, between 1000 and 1999, which are results meaning all went well.

In case all went well, it either calls the callback if given, or returns true.

In case there was a problem, an EPPErrorResponse exception is raised.

# File lib/epp-client/xml.rb, line 50
def get_result(args)
  xml = case args
        when Hash
          args.delete(:xml)
        else
          xml = args
          args = {}
          xml
        end

  args[:range] ||= 1000..1999

  if !(mq = xml.xpath('epp:epp/epp:response/epp:msgQ', EPPClient::SCHEMAS_URL)).empty?
    @msgQ_count = mq.attribute('count').value.to_i
    @msgQ_id = mq.attribute('id').value
    puts "DEBUG: MSGQ : count=#{@msgQ_count}, id=#{@msgQ_id}\n" if debug
  else
    @msgQ_count = 0
    @msgQ_id = nil
  end

  unless (trID = xml.xpath('epp:epp/epp:response/epp:trID', EPPClient::SCHEMAS_URL)).empty?
    @trID = get_trid(trID)
  end

  res = xml.xpath('epp:epp/epp:response/epp:result', EPPClient::SCHEMAS_URL)
  code = res.attribute('code').value.to_i

  raise EPPClient::EPPErrorResponse.new(:xml => xml, :code => code, :message => res.xpath('epp:msg', EPPClient::SCHEMAS_URL).text) unless args[:range].include?(code)

  return true unless args.key?(:callback)

  case cb = args[:callback]
  when Symbol
    return send(cb, xml.xpath('epp:epp/epp:response', EPPClient::SCHEMAS_URL))
  else
    raise ArgumentError, 'Invalid callback type'
  end
end
get_trid(xml) click to toggle source
# File lib/epp-client/xml.rb, line 90
def get_trid(xml)
  {
    :clTRID => xml.xpath('epp:clTRID', EPPClient::SCHEMAS_URL).text,
    :svTRID => xml.xpath('epp:svTRID', EPPClient::SCHEMAS_URL).text,
  }
end
insert_extension(xml1, xml2, pattern = //) click to toggle source

Insert xml2 in xml1 before pattern

# File lib/epp-client/xml.rb, line 143
def insert_extension(xml1, xml2, pattern = /<clTRID>/)
  xml1.sub(pattern, "#{xml2}\\&")
end

Private Instance Methods

parse_xml(string) click to toggle source

Parses a frame and returns a Nokogiri::XML::Document.

# File lib/epp-client/xml.rb, line 7
def parse_xml(string) #:doc:
  Nokogiri::XML::Document.parse(string) do |opts|
    opts.options = 0
    opts.noblanks
  end
end