Module: EPPClient::Connection
- Included in:
- Base
- Defined in:
- lib/epp-client/connection.rb
Overview
This handles all the basic I/O for the connection.
Instance Attribute Summary collapse
-
#recv_frame ⇒ Object
readonly
Returns the value of attribute recv_frame.
-
#sent_frame ⇒ Object
readonly
Returns the value of attribute sent_frame.
-
#srv_ext ⇒ Object
readonly
Returns the value of attribute srv_ext.
-
#srv_lang ⇒ Object
readonly
Returns the value of attribute srv_lang.
-
#srv_ns ⇒ Object
readonly
Returns the value of attribute srv_ns.
-
#srv_version ⇒ Object
readonly
Returns the value of attribute srv_version.
Instance Method Summary collapse
-
#close_connection ⇒ Object
Gracefully close the connection.
-
#greeting_process(xml) ⇒ Object
:nodoc:.
-
#one_frame ⇒ Object
gets a frame from the socket and returns the parsed response.
-
#open_connection ⇒ Object
Establishes the connection to the server, if successful, will return the greeting frame.
-
#send_frame(xml) ⇒ Object
sends a frame.
-
#send_request(xml) ⇒ Object
Sends a frame and returns the server’s answer.
Instance Attribute Details
#recv_frame ⇒ Object (readonly)
Returns the value of attribute recv_frame.
4 5 6 |
# File 'lib/epp-client/connection.rb', line 4 def recv_frame @recv_frame end |
#sent_frame ⇒ Object (readonly)
Returns the value of attribute sent_frame.
4 5 6 |
# File 'lib/epp-client/connection.rb', line 4 def sent_frame @sent_frame end |
#srv_ext ⇒ Object (readonly)
Returns the value of attribute srv_ext.
4 5 6 |
# File 'lib/epp-client/connection.rb', line 4 def srv_ext @srv_ext end |
#srv_lang ⇒ Object (readonly)
Returns the value of attribute srv_lang.
4 5 6 |
# File 'lib/epp-client/connection.rb', line 4 def srv_lang @srv_lang end |
#srv_ns ⇒ Object (readonly)
Returns the value of attribute srv_ns.
4 5 6 |
# File 'lib/epp-client/connection.rb', line 4 def srv_ns @srv_ns end |
#srv_version ⇒ Object (readonly)
Returns the value of attribute srv_version.
4 5 6 |
# File 'lib/epp-client/connection.rb', line 4 def srv_version @srv_version end |
Instance Method Details
#close_connection ⇒ Object
Gracefully close the connection
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/epp-client/connection.rb', line 34 def close_connection if defined?(@socket) && @socket.is_a?(OpenSSL::SSL::SSLSocket) @socket.close @socket = nil end if defined?(@tcpserver) && @tcpserver.is_a?(TCPSocket) @tcpserver.close @tcpserver = nil end return true if @tcpserver.nil? && @socket.nil? end |
#greeting_process(xml) ⇒ Object
:nodoc:
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/epp-client/connection.rb', line 22 def greeting_process(xml) #:nodoc: @srv_version = xml.xpath('epp:epp/epp:greeting/epp:svcMenu/epp:version', EPPClient::SCHEMAS_URL).map(&:text) @srv_lang = xml.xpath('epp:epp/epp:greeting/epp:svcMenu/epp:lang', EPPClient::SCHEMAS_URL).map(&:text) @srv_ns = xml.xpath('epp:epp/epp:greeting/epp:svcMenu/epp:objURI', EPPClient::SCHEMAS_URL).map(&:text) unless (ext = xml.xpath('epp:epp/epp:greeting/epp:svcMenu/epp:svcExtension/epp:extURI', EPPClient::SCHEMAS_URL)).empty? @srv_ext = ext.map(&:text) end xml end |
#one_frame ⇒ Object
gets a frame from the socket and returns the parsed response.
62 63 64 65 66 67 68 |
# File 'lib/epp-client/connection.rb', line 62 def one_frame size = @socket.read(4) raise SocketError, @socket.eof? ? 'Connection closed by remote server' : 'Error reading frame from remote server' if size.nil? size = size.unpack('N')[0] @recv_frame = @socket.read(size - 4) recv_frame_to_xml end |
#open_connection ⇒ Object
Establishes the connection to the server, if successful, will return the greeting frame.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/epp-client/connection.rb', line 8 def open_connection @tcpserver = TCPSocket.new(server, port) @socket = OpenSSL::SSL::SSLSocket.new(@tcpserver, @context) # Synchronously close the connection & socket @socket.sync_close # Connect @socket.connect # Get the initial greeting frame greeting_process(one_frame) end |
#send_frame(xml) ⇒ Object
sends a frame
55 56 57 58 59 |
# File 'lib/epp-client/connection.rb', line 55 def send_frame(xml) @sent_frame = xml @socket.write([xml.size + 4].pack('N') + xml) sent_frame_to_xml end |
#send_request(xml) ⇒ Object
Sends a frame and returns the server’s answer
49 50 51 52 |
# File 'lib/epp-client/connection.rb', line 49 def send_request(xml) send_frame(xml) one_frame end |