Class: EPP::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/epp-client/request.rb

Overview

An EPP XML Request

Direct Known Subclasses

HelloRequest

Instance Method Summary collapse

Constructor Details

#initialize(command, payload, transaction_id) ⇒ Request #initialize(command, transaction_id) {|xml| ... } ⇒ Request

Create new instance of EPP::Request.

Overloads:

  • #initialize(command, payload, transaction_id) ⇒ Request

    Parameters:

    • command (String, #to_s)

      EPP Command to call

    • payload (XML::Node, XML::Document, String)

      XML Payload to transmit

    • transaction_id (String)

      EPP Transaction ID

  • #initialize(command, transaction_id) {|xml| ... } ⇒ Request

    Parameters:

    • command (String, #to_s)

      EPP Command to call

    • transaction_id (String)

      EPP Transaction ID

    Yields:

    • (xml)

      block to construct payload

    Yield Parameters:

    • xml (XML::Node)

      XML Node of the command for the payload to be added into



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/epp-client/request.rb', line 16

def initialize(command, *args, &block)
  @command = XML::Node.new(command)

  cmd = XML::Node.new('command')
  cmd << @command
  xml.root << cmd

  if block_given?
    tid, _ = args
    case block.arity
    when 1
      block.call(@command)
    else
      @command << block.call
    end
  else
    payload, tid = args
    unless payload.nil?
      @command << case payload.class
        when XML::Node
          payload
        when XML::Document
          xml.import(payload.root)
        else
          doc = XML::Parser.string(payload.to_s).parse
          xml.import(doc.root)
      end
    end
  end

  unless command == 'logout'
    cmd << XML::Node.new('clTRID', tid || 'ABC-12345')
  end
end

Instance Method Details

#commandString

Name of the receivers command

Returns:

  • (String)

    command name



53
54
55
# File 'lib/epp-client/request.rb', line 53

def command
  @command.name
end

#inspectObject

See Also:

  • Object#inspect


71
72
73
# File 'lib/epp-client/request.rb', line 71

def inspect
  xml.inspect
end

#to_s(opts = {}) ⇒ Object

Convert the receiver to a string

Parameters:

  • opts (Hash) (defaults to: {})

    Formatting options, passed to the XML::Document



66
67
68
# File 'lib/epp-client/request.rb', line 66

def to_s(opts = {})
  xml.to_s({:indent => false}.merge(opts))
end

#to_xmlXML::Document

Receiver in XML form

Returns:

  • (XML::Document)

    XML of the receiver



59
60
61
# File 'lib/epp-client/request.rb', line 59

def to_xml
  xml
end