class KonoEppClient::Server
Attributes
Public Class Methods
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” -
:old_server
- Set to true to read and write frames in a way that is compatible with older EPP servers. Default is false. -
: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”.
# File lib/epp/server.rb, line 25 def initialize(attributes = {}) requires!(attributes, :tag, :password, :server) @tag = attributes[:tag] @password = attributes[:password] @server = attributes[:server] @port = attributes[:port] || 700 @old_server = attributes[:old_server] || false @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" @transport = attributes[:transport] || :tcp @timeout = attributes[:timeout] || 30 @logged_in = false end
Public Instance Methods
# File lib/epp/server.rb, line 88 def change_password( new_password ) login = KonoEppLogin.new( tag, password ) # FIXME: Order matters login.new_password = new_password login.version = version login.lang = lang login.services = services login.extensions = extensions send_command( login ) end
Closes the connection to the EPP server.
# File lib/epp/server.rb, line 50 def close_connection @connection.close end
# File lib/epp/server.rb, line 43 def connect_and_hello open_connection hello end
# File lib/epp/server.rb, line 126 def create_contact( options ) contact = KonoEppCreateContact.new options send_command( contact ) end
# File lib/epp/server.rb, line 141 def create_domain( options ) domain = KonoEppCreateDomain.new options send_command( domain ) end
# File lib/epp/server.rb, line 131 def delete_contact( id ) contact = KonoEppDeleteContact.new id send_command( contact ) end
# File lib/epp/server.rb, line 151 def delete_domain( name ) domain = KonoEppDeleteDomain.new name send_command( domain ) end
FIXME: Remove command wrappers?
# File lib/epp/server.rb, line 114 def hello response = Hpricot.XML( send_request( KonoEppHello.new.to_s ) ) end
# File lib/epp/server.rb, line 156 def info_contact( id ) contact = KonoEppInfoContact.new id send_command( contact ) end
# File lib/epp/server.rb, line 161 def info_domain( name ) info = KonoEppInfoDomain.new name send_command( info ) end
# File lib/epp/server.rb, line 103 def logged_in? begin poll rescue return false end return true end
Sends a standard login request to the EPP server.
# File lib/epp/server.rb, line 75 def login login = KonoEppLogin.new( tag, password ) # FIXME: Order matters login.version = version login.lang = lang login.services = services login.extensions = extensions send_command( login ) end
Sends a standard logout request to the EPP server.
# File lib/epp/server.rb, line 172 def logout send_command( KonoEppLogout.new, 1500 ) end
Establishes the connection to the server. If the connection is established, then this method will call read and return the EPP <greeting>
which is sent by the server upon connection.
# File lib/epp/server.rb, line 243 def open_connection Timeout.timeout @timeout do @connection = case @transport when :tcp then KonoEppClient::Transport::TcpTransport.new( server, port ) when :http then KonoEppClient::Transport::HttpTransport.new( server, port ) end end end
# File lib/epp/server.rb, line 118 def poll( id = nil ) poll = KonoEppPoll.new( id ? :ack : :req ) poll.ack_id = id if id send_command( poll ) end
Receive an EPP response 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.
# File lib/epp/server.rb, line 257 def read Timeout.timeout @timeout do @connection.read end end
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.
# File lib/epp/server.rb, line 58 def request( xml ) # open_connection # @logged_in = true if login begin @response = send_request( xml ) ensure if @logged_in && !old_server @logged_in = false if logout end end return @response end
# File lib/epp/server.rb, line 184 def send_command( command, expected_result = 1000..1999 ) namespaces = { 'extepp' => 'http://www.nic.it/ITNIC-EPP/extepp-2.0', 'xmlns' => "urn:ietf:params:xml:ns:epp-1.0" } xml = Nokogiri.XML( send_request( command.to_s ) ) # TODO: multiple <response> RFC 3730 §2.6 result = xml.at_xpath( "/xmlns:epp/xmlns:response[1]/xmlns:result", namespaces ) raise KonoEppErrorResponse.new( :message => 'Malformed response' ) if result.nil? xmlns_code = result.at_xpath( "@code" ) raise KonoEppErrorResponse.new( :message => 'Malformed response' ) if xmlns_code.nil? response_code = xmlns_code.value.to_i xmlns_msg = result.xpath( "xmlns:msg/text ()", namespaces ) raise KonoEppErrorResponse.new( :message => 'Malformed response' ) if xmlns_msg.empty? result_message = xmlns_msg.text.strip # TODO: value xmlns_ext_reason = result.xpath( "xmlns:extValue/xmlns:reason", namespaces) result_message += ": #{xmlns_ext_reason.text.strip}" unless xmlns_ext_reason.empty? xmlns_reason_code = result.xpath( "xmlns:extValue/xmlns:value/extepp:reasonCode", namespaces ) reason_code = xmlns_reason_code.text.strip.to_i unless xmlns_reason_code.empty? credit_msg = xml.xpath( "//extepp:credit/text ()", namespaces ) @credit = credit_msg.text.to_f unless credit_msg.empty? if expected_result === response_code return xml end args = { :xml => xml, :response_code => response_code, :reason_code => reason_code, :message => result_message } case [ response_code, reason_code ] when [2200, 6004] raise KonoEppAuthenticationPasswordExpired.new( args ) when [2002, 4015] raise KonoEppLoginNeeded.new( args ) else raise KonoEppErrorResponse.new( args ) end end
private Wrapper which sends XML to the server, and receives the response in return.
# File lib/epp/server.rb, line 179 def send_request( xml ) write( xml ) read end
# File lib/epp/server.rb, line 166 def transfer_domain( name, authinfo, op ) transfer = KonoEppTransferDomain.new name, authinfo, op send_command( transfer ) end
# File lib/epp/server.rb, line 136 def update_contact( options ) contact = KonoEppUpdateContact.new options send_command( contact ) end
# File lib/epp/server.rb, line 146 def update_domain( options ) domain = KonoEppUpdateDomain.new options send_command( domain ) end
Send XML to the server. If the socket returns EOF, the connection has closed and a SocketError is raised.
# File lib/epp/server.rb, line 265 def write( xml ) Timeout.timeout @timeout do @connection.write( xml ) end end