Class: Epp::Server
- Inherits:
-
Object
- Object
- Epp::Server
- Includes:
- REXML, RequiresParameters
- Defined in:
- lib/epp/server.rb
Instance Attribute Summary collapse
-
#extensions ⇒ Object
Returns the value of attribute extensions.
-
#lang ⇒ Object
Returns the value of attribute lang.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#server ⇒ Object
Returns the value of attribute server.
-
#services ⇒ Object
Returns the value of attribute services.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#close_connection ⇒ Object
Closes the connection to the EPP server.
-
#get_frame ⇒ Object
Receive an EPP frame from the server.
-
#header_size(header) ⇒ Object
Returns size of header of response from the EPP server.
-
#initialize(attributes = {}) ⇒ Server
constructor
Required Attrbiutes.
- #new_epp_request ⇒ Object
-
#open_connection ⇒ Object
established, then this method will call get_frame and return the EPP
<greeting>
frame which is sent by the server upon connection. -
#packed(xml) ⇒ Object
Pack the XML as a header for the EPP server.
-
#request(xml) ⇒ Object
Sends an XML request to the EPP server, and receives an XML response.
-
#send_frame(xml) ⇒ Object
Send an XML frame to the server.
-
#send_request(xml) ⇒ Object
Wrapper which sends an XML frame to the server, and receives the response frame in return.
Methods included from RequiresParameters
Constructor Details
#initialize(attributes = {}) ⇒ Server
Required Attrbiutes
-
:server
- The EPP server to connect to -
:tag
- The tag or username used with<login>
requests. -
:password
- The password used with<login>
requests.
Optional Attributes
-
:port
- The EPP standard port is 700. However, you can choose a different port to use. -
:clTRID
- The client transaction identifier is an element that EPP specifies MAY be used to uniquely identify the command to the server. You are responsible for maintaining your own transaction identifier space to ensure uniqueness. Defaults to “ABC-12345” -
:lang
- Set custom language attribute. Default is ‘en’. -
:services
- Use custom EPP services in the <login> frame. The defaults use the EPP standard domain, contact and host 1.0 services. -
:extensions
- URLs to custom extensions to standard EPP. Use these to extend the standard EPP (e.g., Nominet uses extensions). Defaults to none. -
:version
- Set the EPP version. Defaults to “1.0”.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/epp/server.rb', line 22 def initialize(attributes = {}) requires!(attributes, :tag, :password, :server) @tag = attributes[:tag] @password = attributes[:password] @server = attributes[:server] @port = attributes[:port] || 700 @lang = attributes[:lang] || "en" @services = attributes[:services] || ["urn:ietf:params:xml:ns:domain-1.0", "urn:ietf:params:xml:ns:contact-1.0", "urn:ietf:params:xml:ns:host-1.0"] @extensions = attributes[:extensions] || [] @version = attributes[:version] || "1.0" @logged_in = false end |
Instance Attribute Details
#extensions ⇒ Object
Returns the value of attribute extensions.
6 7 8 |
# File 'lib/epp/server.rb', line 6 def extensions @extensions end |
#lang ⇒ Object
Returns the value of attribute lang.
6 7 8 |
# File 'lib/epp/server.rb', line 6 def lang @lang end |
#password ⇒ Object
Returns the value of attribute password.
6 7 8 |
# File 'lib/epp/server.rb', line 6 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
6 7 8 |
# File 'lib/epp/server.rb', line 6 def port @port end |
#server ⇒ Object
Returns the value of attribute server.
6 7 8 |
# File 'lib/epp/server.rb', line 6 def server @server end |
#services ⇒ Object
Returns the value of attribute services.
6 7 8 |
# File 'lib/epp/server.rb', line 6 def services @services end |
#tag ⇒ Object
Returns the value of attribute tag.
6 7 8 |
# File 'lib/epp/server.rb', line 6 def tag @tag end |
#version ⇒ Object
Returns the value of attribute version.
6 7 8 |
# File 'lib/epp/server.rb', line 6 def version @version end |
Instance Method Details
#close_connection ⇒ Object
Closes the connection to the EPP server.
94 95 96 97 98 99 100 |
# File 'lib/epp/server.rb', line 94 def close_connection @socket.close if @socket and not @socket.closed? @connection.close if @connection and not @connection.closed? @socket = @connection = nil return true end |
#get_frame ⇒ Object
Receive an EPP frame from the server. Since the connection is blocking, this method will wait until the connection becomes available for use. If the connection is broken, a SocketError will be raised. Otherwise, it will return a string containing the XML from the server.
106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/epp/server.rb', line 106 def get_frame raise SocketError.new("Connection closed by remote server") if !@socket or @socket.eof? header = @socket.read(4) raise SocketError.new("Error reading frame from remote server") if header.nil? length = header_size(header) raise SocketError.new("Got bad frame header length of #{length} bytes from the server") if length < 5 response = @socket.read(length - 4) end |
#header_size(header) ⇒ Object
Returns size of header of response from the EPP server.
133 134 135 136 |
# File 'lib/epp/server.rb', line 133 def header_size(header) unpacked_header = header.unpack("N") unpacked_header[0] end |
#new_epp_request ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/epp/server.rb', line 37 def new_epp_request xml = Document.new xml << XMLDecl.new("1.0", "UTF-8", "no") xml.add_element("epp", { "xmlns" => "urn:ietf:params:xml:ns:epp-1.0", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation" => "urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd" }) return xml end |
#open_connection ⇒ Object
established, then this method will call get_frame and return the EPP <greeting>
frame which is sent by the server upon connection.
83 84 85 86 87 88 89 90 91 |
# File 'lib/epp/server.rb', line 83 def open_connection @connection = TCPSocket.new(server, port) @socket = OpenSSL::SSL::SSLSocket.new(@connection) if @connection @socket.sync_close = true @socket.connect get_frame end |
#packed(xml) ⇒ Object
Pack the XML as a header for the EPP server.
128 129 130 |
# File 'lib/epp/server.rb', line 128 def packed(xml) [xml.size + 4].pack("N") end |
#request(xml) ⇒ Object
Sends an XML request to the EPP server, and receives an XML response. <login>
and <logout>
requests are also wrapped around the request, so we can close the socket immediately after the request is made.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/epp/server.rb', line 54 def request(xml) open_connection @logged_in = true if login begin @response = send_request(xml) ensure if @logged_in @logged_in = false if logout end close_connection end return @response end |
#send_frame(xml) ⇒ Object
Send an XML frame to the server. Should return the total byte size of the frame sent to the server. If the socket returns EOF, the connection has closed and a SocketError is raised.
123 124 125 |
# File 'lib/epp/server.rb', line 123 def send_frame(xml) @socket.write(packed(xml) + xml) end |
#send_request(xml) ⇒ Object
Wrapper which sends an XML frame to the server, and receives the response frame in return.
74 75 76 77 |
# File 'lib/epp/server.rb', line 74 def send_request(xml) send_frame(xml) get_frame end |