From c602856fe4980df9cbd5d01e01f102549b84d88f Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Tue, 22 Jul 2014 18:19:13 -0300 Subject: [PATCH 01/29] added namespace support and authInfo to contact check --- lib/epp-client/contact.rb | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/epp-client/contact.rb b/lib/epp-client/contact.rb index 230568f..038ff68 100644 --- a/lib/epp-client/contact.rb +++ b/lib/epp-client/contact.rb @@ -2,17 +2,25 @@ module EPPClient module Contact EPPClient::Poll::PARSERS['contact:infData'] = :contact_info_process - def contact_check_xml(*contacts) #:nodoc: - command do |xml| - xml.check do - xml.check('xmlns' => EPPClient::SCHEMAS_URL['contact-1.0']) do - contacts.each do |c| - xml.id(c) - end - end - end - end - end + CONTACT_NS = 'contact' + + def contact_check_xml(contacts) + command do |xml| + xml.check do + xml.check do + xml.parent.namespace = xml.parent.add_namespace_definition(CONTACT_NS, EPPClient::SCHEMAS_URL[CONTACT_NS]) + contacts[:ids].each do |contact| + xml[CONTACT_NS].id contact + end + if contacts.key?(:authInfo) + xml[CONTACT_NS].authInfo do + xml[CONTACT_NS].pw(contacts[:authInfo]) + end + end + end + end + end + end # Check the availability of contacts # From 8d3b7a13bded6e38aff354072ae665dfdcd3f36c Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Tue, 22 Jul 2014 18:23:55 -0300 Subject: [PATCH 02/29] fixed contact check response. It was showing only the last record queried --- lib/epp-client/contact.rb | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/epp-client/contact.rb b/lib/epp-client/contact.rb index 038ff68..93f7a49 100644 --- a/lib/epp-client/contact.rb +++ b/lib/epp-client/contact.rb @@ -40,18 +40,20 @@ def contact_check(*contacts) get_result(:xml => response, :callback => :contact_check_process) end - def contact_check_process(xml) #:nodoc: - xml.xpath('epp:resData/contact:chkData/contact:cd', EPPClient::SCHEMAS_URL).map do |dom| - ret = { - :name => dom.xpath('contact:id', EPPClient::SCHEMAS_URL).text, - :avail => dom.xpath('contact:id', EPPClient::SCHEMAS_URL).attr('avail').value == '1', - } - unless (reason = dom.xpath('contact:reason', EPPClient::SCHEMAS_URL).text).empty? - ret[:reason] = reason - end - ret - end - end + def contact_check_process(xml) + ret = xml.xpath('epp:resData/contact:chkData/contact:cd', EPPClient::SCHEMAS_URL).map do |dom| + res = { + :name => dom.xpath('contact:id', EPPClient::SCHEMAS_URL).text, + :avail => dom.xpath('contact:id', EPPClient::SCHEMAS_URL).attr('avail').value == '1', + } + + unless (reason = dom.xpath('contact:reason', EPPClient::SCHEMAS_URL).text).empty? + res[:reason] = reason + end + res + end + ret + end def contact_info_xml(args) #:nodoc: command do |xml| From 14519a4445b0cca8bc20c5cfcebc97240f39d629 Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Tue, 22 Jul 2014 18:27:01 -0300 Subject: [PATCH 03/29] added namespace support to contact info --- lib/epp-client/contact.rb | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/epp-client/contact.rb b/lib/epp-client/contact.rb index 93f7a49..25b3132 100644 --- a/lib/epp-client/contact.rb +++ b/lib/epp-client/contact.rb @@ -55,20 +55,21 @@ def contact_check_process(xml) ret end - def contact_info_xml(args) #:nodoc: - command do |xml| - xml.info do - xml.info('xmlns' => EPPClient::SCHEMAS_URL['contact-1.0']) do - xml.id(args[:id]) - if args.key?(:authInfo) - xml.authInfo do - xml.pw(args[:authInfo]) - end - end - end - end - end - end + def contact_info_xml(contact) + command do |xml| + xml.info do + xml.info do + xml.parent.namespace = xml.parent.add_namespace_definition(CONTACT_NS, EPPClient::SCHEMAS_URL[CONTACT_NS]) + xml[CONTACT_NS].id contact[:id] + end + if contact.key?(:authInfo) + xml[CONTACT_NS].authInfo do + xml[CONTACT_NS].pw(contact[:authInfo]) + end + end + end + end + end # Returns the informations about a contact # From 3428a3c3c349d37828f6822f768db11317a7f446 Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Tue, 22 Jul 2014 18:41:50 -0300 Subject: [PATCH 04/29] added namespace support to contact create --- lib/epp-client/contact.rb | 89 +++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/lib/epp-client/contact.rb b/lib/epp-client/contact.rb index 25b3132..f18e27a 100644 --- a/lib/epp-client/contact.rb +++ b/lib/epp-client/contact.rb @@ -196,53 +196,50 @@ def contact_info_process(xml) #:nodoc: ret end - def contact_create_xml(contact) #:nodoc: - command do |xml| - xml.create do - xml.create('xmlns' => EPPClient::SCHEMAS_URL['contact-1.0']) do - if contact.key?(:id) - xml.id(contact[:id]) - else - xml.id('invalid') - end - contact[:postalInfo].each do |type,infos| - xml.postalInfo :type => type do - xml.name(infos[:name]) - xml.org(infos[:org]) if infos.key?(:org) - xml.addr do - infos[:addr][:street].each do |street| - xml.street(street) - end - xml.city(infos[:addr][:city]) - [:sp, :pc].each do |val| - xml.__send__(val, infos[:addr][val]) if infos[:addr].key?(val) - end - xml.cc(infos[:addr][:cc]) - end - end - end - [:voice, :fax].each do |val| - xml.__send__(val, contact[val]) if contact.key?(val) - end - xml.email(contact[:email]) - xml.authInfo do - xml.pw(contact[:authInfo]) - end - if contact.key?(:disclose) - xml.disclose do - contact[:disclose].each do |disc| - if disc.key?(:type) - xml.__send__(disc[:name], :type => disc[:type]) - else - xml.__send__(disc[:name]) - end + def contact_create_xml(contact) #:nodoc: + command do |xml| + xml.create do + xml.create do + xml.parent.namespace = xml.parent.add_namespace_definition(CONTACT_NS, EPPClient::SCHEMAS_URL[CONTACT_NS]) + xml[CONTACT_NS].id contact.key?(:id) ? contact[:id] : 'dummy' + contact[:postalInfo].each do |type,infos| + xml[CONTACT_NS].postalInfo :type => type do + xml[CONTACT_NS].name infos[:name] + xml[CONTACT_NS].org infos[:org] if infos.key?(:org) + xml[CONTACT_NS].addr do + infos[:addr][:street].each do |street| + xml[CONTACT_NS].street street + end + xml[CONTACT_NS].city infos[:addr][:city] + [:sp, :pc].each do |val| + xml[CONTACT_NS].__send__(val, infos[:addr][val]) if infos[:addr].key?(val) + end + xml[CONTACT_NS].cc infos[:addr][:cc] + end + end + end + [:voice, :fax].each do |val| + xml[CONTACT_NS].__send__(val, contact[val]) if contact.key?(val) + end + xml[CONTACT_NS].email contact[:email] + xml[CONTACT_NS].authInfo do + xml[CONTACT_NS].pw contact[:authInfo] + end + if contact.key?(:disclose) + xml[CONTACT_NS].disclose do + contact[:disclose].each do |disc| + if disc.key?(:type) + xml[CONTACT_NS].__send__(disc[:name], :type => disc[:type]) + else + xml[CONTACT_NS].__send__(disc[:name]) + end + end + end + end + end + end + end end - end - end - end - end - end - end # Creates a contact # From 2991a86483c057a48d820a99e1585fd6ffb8e351 Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Tue, 22 Jul 2014 18:43:26 -0300 Subject: [PATCH 05/29] added namespace support to contact delete --- lib/epp-client/contact.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/epp-client/contact.rb b/lib/epp-client/contact.rb index f18e27a..6fda59d 100644 --- a/lib/epp-client/contact.rb +++ b/lib/epp-client/contact.rb @@ -295,14 +295,15 @@ def contact_create_process(xml) #:nodoc: end def contact_delete_xml(contact) #:nodoc: - command do |xml| - xml.delete do - xml.delete('xmlns' => EPPClient::SCHEMAS_URL['contact-1.0']) do - xml.id(contact) - end - end - end - end + command do |xml| + xml.delete do + xml.delete do + xml.parent.namespace = xml.parent.add_namespace_definition(CONTACT_NS, EPPClient::SCHEMAS_URL[CONTACT_NS]) + xml[CONTACT_NS].id(contact) + end + end + end + end # Deletes a contact # From b47e6512e4b0035e0a1ca9d6f68d3bb7762c13ef Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Wed, 23 Jul 2014 11:27:23 -0300 Subject: [PATCH 06/29] added namespace support to domain check --- lib/epp-client/domain.rb | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/epp-client/domain.rb b/lib/epp-client/domain.rb index 27c5c60..5ce372f 100644 --- a/lib/epp-client/domain.rb +++ b/lib/epp-client/domain.rb @@ -3,16 +3,20 @@ module Domain EPPClient::Poll::PARSERS['domain:panData'] = :domain_pending_action_process EPPClient::Poll::PARSERS['domain:trnData'] = :domain_transfer_response + DOMAIN_NS = 'domain' + def domain_check_xml(*domains) # :nodoc: - command do |xml| - xml.check do - xml.check('xmlns' => EPPClient::SCHEMAS_URL['domain-1.0']) do - domains.each do |dom| - xml.name(dom) - end - end - end - end + domains.flatten! + command do |xml| + xml.check do + xml.check do + xml.parent.namespace = xml.parent.add_namespace_definition(DOMAIN_NS, EPPClient::SCHEMAS_URL[DOMAIN_NS]) + domains.each do |dom| + xml[DOMAIN_NS].name(dom) + end + end + end + end end # Check the availability of domains From c0b043cb24901fed9e6ae7e7488982df59f716cd Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Wed, 23 Jul 2014 11:28:57 -0300 Subject: [PATCH 07/29] added namespace support to domain info --- lib/epp-client/domain.rb | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/epp-client/domain.rb b/lib/epp-client/domain.rb index 5ce372f..76bf479 100644 --- a/lib/epp-client/domain.rb +++ b/lib/epp-client/domain.rb @@ -48,22 +48,27 @@ def domain_check_process(xml) # :nodoc: end def domain_info_xml(args) # :nodoc: - command do |xml| - xml.info do - xml.info('xmlns' => EPPClient::SCHEMAS_URL['domain-1.0']) do - xml.name(args[:name]) - if args.key?(:authInfo) - xml.authInfo do - if args.key?(:roid) - xml.pw({:roid => args[:roid]}, args[:authInfo]) - else - xml.pw(args[:authInfo]) - end - end - end - end - end - end + command do |xml| + xml.info do + xml.info do + xml.parent.namespace = xml.parent.add_namespace_definition(DOMAIN_NS, EPPClient::SCHEMAS_URL[DOMAIN_NS]) + if args.key?(:hosts) + xml[DOMAIN_NS].name(args[:name],:hosts=>args[:hosts]) + else + xml[DOMAIN_NS].name(args[:name]) + end + if args.key?(:authInfo) + xml[DOMAIN_NS].authInfo do + if args.key?(:roid) + xml[DOMAIN_NS].pw({:roid => args[:roid]}, args[:authInfo]) + else + xml[DOMAIN_NS].pw(args[:authInfo]) + end + end + end + end + end + end end # Returns the informations about a domain From a0e55e1b18c1d7d90dd1bf450d04d3c0ad804604 Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Wed, 23 Jul 2014 11:40:29 -0300 Subject: [PATCH 08/29] added crID field to domain info response --- lib/epp-client/domain.rb | 78 ++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/lib/epp-client/domain.rb b/lib/epp-client/domain.rb index 76bf479..12fd63f 100644 --- a/lib/epp-client/domain.rb +++ b/lib/epp-client/domain.rb @@ -50,7 +50,7 @@ def domain_check_process(xml) # :nodoc: def domain_info_xml(args) # :nodoc: command do |xml| xml.info do - xml.info do + xml.info do xml.parent.namespace = xml.parent.add_namespace_definition(DOMAIN_NS, EPPClient::SCHEMAS_URL[DOMAIN_NS]) if args.key?(:hosts) xml[DOMAIN_NS].name(args[:name],:hosts=>args[:hosts]) @@ -131,55 +131,55 @@ def domain_info(args) def domain_info_process(xml) # :nodoc: dom = xml.xpath('epp:resData/domain:infData', EPPClient::SCHEMAS_URL) ret = { - :name => dom.xpath('domain:name', EPPClient::SCHEMAS_URL).text, - :roid => dom.xpath('domain:roid', EPPClient::SCHEMAS_URL).text, + :name => dom.xpath('domain:name', EPPClient::SCHEMAS_URL).text, + :roid => dom.xpath('domain:roid', EPPClient::SCHEMAS_URL).text, } if (status = dom.xpath('domain:status', EPPClient::SCHEMAS_URL)).size > 0 - ret[:status] = status.map {|s| s.attr('s')} + ret[:status] = status.map {|s| s.attr('s')} end if (registrant = dom.xpath('domain:registrant', EPPClient::SCHEMAS_URL)).size > 0 - ret[:registrant] = registrant.text + ret[:registrant] = registrant.text end if (contact = dom.xpath('domain:contact', EPPClient::SCHEMAS_URL)).size > 0 - ret[:contacts] = contact.inject({}) do |a,c| - s = c.attr('type').to_sym - a[s] ||= [] - a[s] << c.text - a - end + ret[:contacts] = contact.inject({}) do |a,c| + s = c.attr('type').to_sym + a[s] ||= [] + a[s] << c.text + a + end end if (ns = dom.xpath('domain:ns', EPPClient::SCHEMAS_URL)).size > 0 - if (hostObj = ns.xpath('domain:hostObj', EPPClient::SCHEMAS_URL)).size > 0 - ret[:ns] = hostObj.map {|h| h.text} - elsif (hostAttr = ns.xpath('domain:hostAttr', EPPClient::SCHEMAS_URL)).size > 0 - ret[:ns] = hostAttr.map do |h| - r = { :hostName => h.xpath('domain:hostName', EPPClient::SCHEMAS_URL).text } - if (v4 = h.xpath('domain:hostAddr[@ip="v4"]', EPPClient::SCHEMAS_URL)).size > 0 - r[:hostAddrv4] = v4.map {|v| v.text} - end - if (v6 = h.xpath('domain:hostAddr[@ip="v6"]', EPPClient::SCHEMAS_URL)).size > 0 - r[:hostAddrv6] = v6.map {|v| v.text} - end - r - end - end + if (hostObj = ns.xpath('domain:hostObj', EPPClient::SCHEMAS_URL)).size > 0 + ret[:ns] = hostObj.map {|h| h.text} + elsif (hostAttr = ns.xpath('domain:hostAttr', EPPClient::SCHEMAS_URL)).size > 0 + ret[:ns] = hostAttr.map do |h| + r = { :hostName => h.xpath('domain:hostName', EPPClient::SCHEMAS_URL).text } + if (v4 = h.xpath('domain:hostAddr[@ip="v4"]', EPPClient::SCHEMAS_URL)).size > 0 + r[:hostAddrv4] = v4.map {|v| v.text} + end + if (v6 = h.xpath('domain:hostAddr[@ip="v6"]', EPPClient::SCHEMAS_URL)).size > 0 + r[:hostAddrv6] = v6.map {|v| v.text} + end + r + end + end end if (host = dom.xpath('domain:host', EPPClient::SCHEMAS_URL)).size > 0 - ret[:host] = host.map {|h| h.text} - end - %w(clID upID).each do |val| - if (r = dom.xpath("domain:#{val}", EPPClient::SCHEMAS_URL)).size > 0 - ret[val.to_sym] = r.text - end - end - %w(crDate exDate upDate trDate).each do |val| - if (r = dom.xpath("domain:#{val}", EPPClient::SCHEMAS_URL)).size > 0 - ret[val.to_sym] = DateTime.parse(r.text) - end - end - if (authInfo = dom.xpath('domain:authInfo', EPPClient::SCHEMAS_URL)).size > 0 - ret[:authInfo] = authInfo.xpath('domain:pw', EPPClient::SCHEMAS_URL).text + ret[:host] = host.map {|h| h.text} end + %w(clID crID upID).each do |val| + if (r = dom.xpath("domain:#{val}", EPPClient::SCHEMAS_URL)).size > 0 + ret[val.to_sym] = r.text + end + end + %w(crDate exDate upDate trDate).each do |val| + if (r = dom.xpath("domain:#{val}", EPPClient::SCHEMAS_URL)).size > 0 + ret[val.to_sym] = DateTime.parse(r.text) + end + end + if (authInfo = dom.xpath('domain:authInfo', EPPClient::SCHEMAS_URL)).size > 0 + ret[:authInfo] = authInfo.xpath('domain:pw', EPPClient::SCHEMAS_URL).text + end return ret end From 161183253353988746fa12312502d603acebcefa Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Wed, 23 Jul 2014 11:41:17 -0300 Subject: [PATCH 09/29] added namespace support to contatct update --- lib/epp-client/contact.rb | 127 +++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 62 deletions(-) diff --git a/lib/epp-client/contact.rb b/lib/epp-client/contact.rb index 6fda59d..3e8a148 100644 --- a/lib/epp-client/contact.rb +++ b/lib/epp-client/contact.rb @@ -317,70 +317,73 @@ def contact_delete(contact) end def contact_update_xml(args) #:nodoc: - command do |xml| - xml.update do - xml.update('xmlns' => EPPClient::SCHEMAS_URL['contact-1.0']) do - xml.id args[:id] - if args.key?(:add) && args[:add].key?(:status) - xml.add do - args[:add][:status].each do |s| - xml.status :s => s - end - end - end - if args.key?(:rem) && args[:rem].key?(:status) - xml.rem do - args[:rem][:status].each do |s| - xml.status :s => s - end - end - end - if args.key?(:chg) - contact = args[:chg] - xml.chg do - if contact.key?(:postalInfo) - contact[:postalInfo].each do |type,infos| - xml.postalInfo :type => type do - xml.name(infos[:name]) - xml.org(infos[:org]) if infos.key?(:org) - xml.addr do - infos[:addr][:street].each do |street| - xml.street(street) - end - xml.city(infos[:addr][:city]) - [:sp, :pc].each do |val| - xml.__send__(val, infos[:addr][val]) if infos[:addr].key?(val) + command do |xml| + xml.update do + xml.update do + xml.parent.namespace = xml.parent.add_namespace_definition(CONTACT_NS, EPPClient::SCHEMAS_URL[CONTACT_NS]) + xml[CONTACT_NS].id args[:id] + if args.key?(:add) && args[:add].key?(:status) + xml[CONTACT_NS].add do + args[:add][:status].each do |s| + xml[CONTACT_NS].status :s => s + end + end + end + if args.key?(:rem) && args[:rem].key?(:status) + xml[CONTACT_NS].rem do + args[:rem][:status].each do |s| + xml[CONTACT_NS].status :s => s + end + end + end + if args.key?(:chg) + contact = args[:chg] + xml[CONTACT_NS].chg do + if contact.key?(:postalInfo) + contact[:postalInfo].each do |type,infos| + xml[CONTACT_NS].postalInfo :type => type do + xml[CONTACT_NS].name(infos[:name]) if infos.key?(:name) + xml[CONTACT_NS].org(infos[:org]) if infos.key?(:org) + if infos.key?(:addr) + xml[CONTACT_NS].addr do + infos[:addr][:street].each do |street| + xml[CONTACT_NS].street(street) + end + xml[CONTACT_NS].city(infos[:addr][:city]) + [:sp, :pc].each do |val| + xml[CONTACT_NS].__send__(val, infos[:addr][val]) if infos[:addr].key?(val) + end + xml[CONTACT_NS].cc(infos[:addr][:cc]) + end + end + end + end + end + [:voice, :fax, :email].each do |val| + xml[CONTACT_NS].__send__(val, contact[val]) if contact.key?(val) + end + if contact.key?(:authInfo) + xml[CONTACT_NS].authInfo do + xml[CONTACT_NS].pw(contact[:authInfo]) + end + end + if contact.key?(:disclose) + xml[CONTACT_NS].disclose(:flag=>contact[:disclose][:flag]) do + contact[:disclose][:elements].each do |disc| + if disc.is_a?(Hash) + xml[CONTACT_NS].__send__(disc[:name], :type => disc[:type]) + else + xml[CONTACT_NS].__send__(disc) + end + end + end + end + end + end + end + end end - xml.cc(infos[:addr][:cc]) - end - end - end end - [:voice, :fax, :email].each do |val| - xml.__send__(val, contact[val]) if contact.key?(val) - end - if contact.key?(:authInfo) - xml.authInfo do - xml.pw(contact[:authInfo]) - end - end - if contact.key?(:disclose) - xml.disclose do - contact[:disclose].each do |disc| - if disc.key?(:type) - xml.__send__(disc[:name], :type => disc[:type]) - else - xml.__send__(disc[:name]) - end - end - end - end - end - end - end - end - end - end # Updates a contact # From b94af79a040679c467641ce656c904fbac1b546b Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Wed, 23 Jul 2014 11:47:24 -0300 Subject: [PATCH 10/29] added namespace support to domain create --- lib/epp-client/domain.rb | 92 +++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 48 deletions(-) diff --git a/lib/epp-client/domain.rb b/lib/epp-client/domain.rb index 12fd63f..115a0d0 100644 --- a/lib/epp-client/domain.rb +++ b/lib/epp-client/domain.rb @@ -184,64 +184,60 @@ def domain_info_process(xml) # :nodoc: end def domain_nss_xml(xml, nss) #:nodoc: - xml.ns do - if nss.first.is_a?(Hash) - nss.each do |ns| - xml.hostAttr do - xml.hostName ns[:hostName] - if ns.key?(:hostAddrv4) - ns[:hostAddrv4].each do |v4| - xml.hostAddr({:ip => :v4}, v4) - end - end - if ns.key?(:hostAddrv6) - ns[:hostAddrv6].each do |v6| - xml.hostAddr({:ip => :v6}, v6) - end - end - end - end - else - nss.each do |ns| - xml.hostObj ns - end - end + xml[DOMAIN_NS].ns do + if nss.first.is_a?(Hash) + nss.each do |ns| + xml[DOMAIN_NS].hostAttr do + xml[DOMAIN_NS].hostName ns[:hostName] + if ns.key?(:hostAddrv4) + ns[:hostAddrv4].each do |v4| + xml[DOMAIN_NS].hostAddr({:ip => :v4}, v4) + end + end + if ns.key?(:hostAddrv6) + ns[:hostAddrv6].each do |v6| + xml[DOMAIN_NS].hostAddr({:ip => :v6}, v6) + end + end + end + end + else + nss.each do |ns| + xml[DOMAIN_NS].hostObj ns + end + end end end def domain_contacts_xml(xml, args) #:nodoc: args.each do |type,contacts| - contacts.each do |c| - xml.contact({:type => type}, c) - end + contacts.each do |c| + xml[DOMAIN_NS].contact({:type => type}, c) + end end end def domain_create_xml(args) #:nodoc: command do |xml| - xml.create do - xml.create('xmlns' => EPPClient::SCHEMAS_URL['domain-1.0']) do - xml.name args[:name] - - if args.key?(:period) - xml.period({:unit => args[:period][:unit]}, args[:period][:number]) - end - - if args.key?(:ns) - domain_nss_xml(xml, args[:ns]) - end - - xml.registrant args[:registrant] if args.key?(:registrant) - - if args.key?(:contacts) - domain_contacts_xml(xml, args[:contacts]) - end - - xml.authInfo do - xml.pw args[:authInfo] - end - end - end + xml.create do + xml.create do + xml.parent.namespace = xml.parent.add_namespace_definition(DOMAIN_NS, EPPClient::SCHEMAS_URL[DOMAIN_NS]) + xml[DOMAIN_NS].name args[:name] + if args.key?(:period) + xml[DOMAIN_NS].period({:unit => args[:period][:unit]}, args[:period][:number]) + end + if args.key?(:ns) + domain_nss_xml(xml, args[:ns]) + end + xml.registrant args[:registrant] if args.key?(:registrant) + if args.key?(:contacts) + domain_contacts_xml(xml, args[:contacts]) + end + xml[DOMAIN_NS].authInfo do + xml[DOMAIN_NS].pw args[:authInfo] + end + end + end end end From 5539f84ece5839782df7b01165f16c3be0474f4e Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Wed, 23 Jul 2014 11:50:17 -0300 Subject: [PATCH 11/29] added namespace support to domain update --- lib/epp-client/domain.rb | 77 ++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/lib/epp-client/domain.rb b/lib/epp-client/domain.rb index 115a0d0..4fa3879 100644 --- a/lib/epp-client/domain.rb +++ b/lib/epp-client/domain.rb @@ -310,44 +310,45 @@ def domain_delete(domain) def domain_update_xml(args) #:nodoc: command do |xml| - xml.update do - xml.update('xmlns' => EPPClient::SCHEMAS_URL['domain-1.0']) do - xml.name args[:name] - [:add, :rem].each do |ar| - if args.key?(ar) && (args[ar].key?(:ns) || args[ar].key?(:contacts) || args[ar].key?(:status)) - xml.__send__(ar) do - if args[ar].key?(:ns) - domain_nss_xml(xml, args[ar][:ns]) - end - if args[ar].key?(:contacts) - domain_contacts_xml(xml, args[ar][:contacts]) - end - if args[ar].key?(:status) - args[ar][:status].each do |st,text| - if text.nil? - xml.status(:s => st) - else - xml.status({:s => st}, text) - end - end - end - end - end - end - if args.key?(:chg) && (args[:chg].key?(:registrant) || args[:chg].key?(:authInfo)) - xml.chg do - if args[:chg].key?(:registrant) - xml.registrant args[:chg][:registrant] - end - if args[:chg].key?(:authInfo) - xml.authInfo do - xml.pw args[:chg][:authInfo] - end - end - end - end - end - end + xml.update do + xml.update do + xml.parent.namespace = xml.parent.add_namespace_definition(DOMAIN_NS, EPPClient::SCHEMAS_URL[DOMAIN_NS]) + xml[DOMAIN_NS].name args[:name] + [:add, :rem].each do |ar| + if args.key?(ar) && (args[ar].key?(:ns) || args[ar].key?(:contacts) || args[ar].key?(:status)) + xml[DOMAIN_NS].__send__(ar) do + if args[ar].key?(:ns) + domain_nss_xml(xml, args[ar][:ns]) + end + if args[ar].key?(:contacts) + domain_contacts_xml(xml, args[ar][:contacts]) + end + if args[ar].key?(:status) + args[ar][:status].each do |st,text| + if text.nil? + xml[DOMAIN_NS].status(:s => st) + else + xml[DOMAIN_NS].status({:s => st}, text) + end + end + end + end + end + end + if args.key?(:chg) && (args[:chg].key?(:registrant) || args[:chg].key?(:authInfo)) + xml.chg do + if args[:chg].key?(:registrant) + xml[DOMAIN_NS].registrant args[:chg][:registrant] + end + if args[:chg].key?(:authInfo) + xml[DOMAIN_NS].authInfo do + xml[DOMAIN_NS].pw args[:chg][:authInfo] + end + end + end + end + end + end end end From 4207dd96e9bf2b5f67c181ace61462ad3801db7e Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Wed, 23 Jul 2014 11:52:32 -0300 Subject: [PATCH 12/29] added namespace support to domain delete --- lib/epp-client/domain.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/epp-client/domain.rb b/lib/epp-client/domain.rb index 4fa3879..3ca0d60 100644 --- a/lib/epp-client/domain.rb +++ b/lib/epp-client/domain.rb @@ -289,11 +289,12 @@ def domain_create_process(xml) #:nodoc: def domain_delete_xml(domain) #:nodoc: command do |xml| - xml.delete do - xml.delete('xmlns' => EPPClient::SCHEMAS_URL['domain-1.0']) do - xml.name domain - end - end + xml.delete do + xml.delete do + xml.parent.namespace = xml.parent.add_namespace_definition(DOMAIN_NS, EPPClient::SCHEMAS_URL[DOMAIN_NS]) + xml[DOMAIN_NS].name domain + end + end end end From 1fbace1d227199305f2ba48cfd0cceaf61066637 Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Fri, 31 Oct 2014 14:40:15 -0200 Subject: [PATCH 13/29] Replacing Builder::XmlMarkup by Nokogiri::XML::Builder --- lib/epp-client/xml.rb | 89 +++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 38 deletions(-) diff --git a/lib/epp-client/xml.rb b/lib/epp-client/xml.rb index a276988..aba5d58 100644 --- a/lib/epp-client/xml.rb +++ b/lib/epp-client/xml.rb @@ -6,8 +6,8 @@ module XML # Parses a frame and returns a Nokogiri::XML::Document. def parse_xml(string) #:doc: Nokogiri::XML::Document.parse(string) do |opts| - opts.options = 0 - opts.noblanks + opts.options = 0 + opts.noblanks end end private :parse_xml @@ -25,17 +25,17 @@ def sent_frame_to_xml #:nodoc: end def raw_builder(opts = {}) #:nodoc: - xml = Builder::XmlMarkup.new(opts) - yield xml + Nokogiri::XML::Builder.new(opts) do |xml| + yield xml + end end - # creates a Builder::XmlMarkup object, mostly only used by +command+ - def builder(opts = {}) + # creates a Nokogiri::XML::Builder object, mostly only used by +command+ + def builder(opts = {:encoding=>'UTF-8'}) 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 + xml.epp(:xmlns => EPPClient::SCHEMAS_URL['epp']) do + yield xml + end end end @@ -104,47 +104,60 @@ def get_trid(xml) # being the extensions. # # command do |xml| - # xml.logout + # xml.logout # end # # or # # command(lambda do |xml| - # xml.logout - # end, lambda do |xml| - # xml.extension - # end) + # xml.logout + # end, lambda do |xml| + # xml.extension + # end) 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 + ret = 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 + ret.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML).strip end # Wraps the content in an epp:extension. - def extension - raw_builder do |xml| - xml.extension do - yield(xml) - end + # Usage: + # extension do |xml| + # xml[namespace].command(XMLNS) do + # xml.subcommand, k=>v, text + # end + # end + # + # You don't need to set namespace on childs of the node where you defined it + def extension(&block) + ext = raw_builder do |xml| + xml.extension do + yield(xml) + end end + ext.doc.child end - # Insert xml2 in xml1 before pattern - def insert_extension(xml1, xml2, pattern = //) - xml1.sub(pattern, "#{xml2}\\&") + # Insert node in root before clTRID node + def insert_extension(_root,_node) + root = Nokogiri::XML(_root) + node = Nokogiri::XML::DocumentFragment.parse(_node) + root.at('clTRID').add_previous_sibling(node) + root.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML).strip end end end From 7f78265683508c4b6adf69d3305a4421e0548b9c Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Fri, 31 Oct 2014 14:41:03 -0200 Subject: [PATCH 14/29] updating Gemfile.lock --- Gemfile.lock | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index d594964..59cd60d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,31 +1,34 @@ PATH remote: . specs: - epp-client-afnic (0.12.0) + epp-client-afnic (0.13.1) builder (>= 2.1.2) - epp-client-base (= 0.12.0) - epp-client-rgp (= 0.12.0) - epp-client-secdns (= 0.12.0) + epp-client-base (= 0.13.1) + epp-client-rgp (= 0.13.1) + epp-client-secdns (= 0.13.1) nokogiri (~> 1.4) - epp-client-base (0.12.0) + epp-client-base (0.13.1) builder (>= 2.1.2) nokogiri (~> 1.4) - epp-client-rgp (0.12.0) + epp-client-rgp (0.13.1) builder (>= 2.1.2) nokogiri (~> 1.4) - epp-client-secdns (0.12.0) + epp-client-secdns (0.13.1) builder (>= 2.1.2) nokogiri (~> 1.4) - epp-client-smallregistry (0.12.0) + epp-client-smallregistry (0.13.1) builder (>= 2.1.2) - epp-client-base (= 0.12.0) + epp-client-base (= 0.13.1) + epp-client-secdns (= 0.13.1) nokogiri (~> 1.4) GEM remote: http://rubygems.org/ specs: - builder (3.1.4) - nokogiri (1.5.6) + builder (3.2.2) + mini_portile (0.6.0) + nokogiri (1.6.3.1) + mini_portile (= 0.6.0) PLATFORMS ruby From 111ad714263fbe1923ee373e4ebe7e41462fc6c0 Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Fri, 31 Oct 2014 15:00:57 -0200 Subject: [PATCH 15/29] bump to version 0.13.3 --- lib/epp-client/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/epp-client/version.rb b/lib/epp-client/version.rb index 1b491d0..526ba3d 100644 --- a/lib/epp-client/version.rb +++ b/lib/epp-client/version.rb @@ -1,3 +1,3 @@ module EPPClient - VERSION = "0.13.1" + VERSION = "0.13.3" end From e20bb9cbdf27e3d2bd77324bcc5e2c8bd51b1543 Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Fri, 31 Oct 2014 20:28:59 -0200 Subject: [PATCH 16/29] setting env for testing --- Gemfile.lock | 14 ++++++++++++++ Rakefile | 4 ++++ epp-client-base.gemspec | 3 ++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 59cd60d..401762b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -26,9 +26,22 @@ GEM remote: http://rubygems.org/ specs: builder (3.2.2) + diff-lcs (1.2.5) mini_portile (0.6.0) nokogiri (1.6.3.1) mini_portile (= 0.6.0) + rspec (3.1.0) + rspec-core (~> 3.1.0) + rspec-expectations (~> 3.1.0) + rspec-mocks (~> 3.1.0) + rspec-core (3.1.7) + rspec-support (~> 3.1.0) + rspec-expectations (3.1.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.1.0) + rspec-mocks (3.1.3) + rspec-support (~> 3.1.0) + rspec-support (3.1.2) PLATFORMS ruby @@ -40,3 +53,4 @@ DEPENDENCIES epp-client-rgp! epp-client-secdns! epp-client-smallregistry! + rspec diff --git a/Rakefile b/Rakefile index d53a9b1..8447d91 100644 --- a/Rakefile +++ b/Rakefile @@ -3,6 +3,7 @@ require 'rake' require 'rdoc/task' require 'rubygems/package_task' require "bundler/gem_helper" +require 'rspec/core/rake_task' MY_GEMS = Dir['*.gemspec'].map {|g| g.sub(/.*-(.*)\.gemspec/, '\1')} @@ -39,3 +40,6 @@ Rake::RDocTask.new do |rdoc| rdoc.rdoc_files.include('lib/**/*.rb') end +RSpec::Core::RakeTask.new(:spec) + +task :default => :spec diff --git a/epp-client-base.gemspec b/epp-client-base.gemspec index 97cadd5..e311527 100644 --- a/epp-client-base.gemspec +++ b/epp-client-base.gemspec @@ -47,7 +47,8 @@ Gem::Specification.new do |gem| gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") gem.require_paths = ['lib'] - gem.add_development_dependency "bundler", ">= 1.0.0" + gem.add_development_dependency 'bundler', '>= 1.0.0' gem.add_dependency('nokogiri', '~> 1.4') gem.add_dependency('builder', '>= 2.1.2') + gem.add_development_dependency 'rspec' end From 759d31d4ae4ec9268c74b00e9e27adc86551ec3e Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Fri, 31 Oct 2014 20:30:57 -0200 Subject: [PATCH 17/29] fixing authInfo on ContatcInfo --- lib/epp-client/contact.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/epp-client/contact.rb b/lib/epp-client/contact.rb index 3e8a148..845a09f 100644 --- a/lib/epp-client/contact.rb +++ b/lib/epp-client/contact.rb @@ -61,12 +61,12 @@ def contact_info_xml(contact) xml.info do xml.parent.namespace = xml.parent.add_namespace_definition(CONTACT_NS, EPPClient::SCHEMAS_URL[CONTACT_NS]) xml[CONTACT_NS].id contact[:id] - end - if contact.key?(:authInfo) - xml[CONTACT_NS].authInfo do - xml[CONTACT_NS].pw(contact[:authInfo]) - end - end + if contact.key?(:authInfo) + xml[CONTACT_NS].authInfo do + xml[CONTACT_NS].pw(contact[:authInfo]) + end + end + end end end end From 37b80b43d3d1efc3703c3a258291e4ceff11e4a7 Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Fri, 31 Oct 2014 21:03:34 -0200 Subject: [PATCH 18/29] Fixed disclose with no type value on contact info. And added a FIXME to report a missing extension attribute on voice field, also on contact info. --- lib/epp-client/contact.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/epp-client/contact.rb b/lib/epp-client/contact.rb index 845a09f..8fa38e2 100644 --- a/lib/epp-client/contact.rb +++ b/lib/epp-client/contact.rb @@ -128,6 +128,9 @@ def contact_info_xml(contact) # parties. See # section 2.9[http://tools.ietf.org/html/rfc5733#section-2.9] of RFC 5733 # for details. + #-- + #FIXME: :voice could have an "x" attribute for extension + #++ def contact_info(args) if String === args args = {:id => args} @@ -187,8 +190,8 @@ def contact_info_process(xml) #:nodoc: ret[:disclose] = { :flag => disclose.attr('flag').value == '1', :elements => [] } disclose.children.each do |c| r = { :name => c.name } - unless (type = c.attr('type').value).nil? - r[:type] == type + unless (type = c.attr('type')).nil? + r[:type] == type.value end ret[:disclose][:elements] << r end From 2c83c124663bb1e6996d8f6cb379246f622ef51b Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Fri, 31 Oct 2014 21:34:33 -0200 Subject: [PATCH 19/29] added initial tests --- spec/lib/contact_spec.rb | 49 ++++++++++++++++++++++++++++++++++++ spec/lib/domain_spec.rb | 1 + spec/spec_helper.rb | 3 +++ spec/util/test_util.rb | 17 +++++++++++++ spec/xml/contact_check_c.xml | 14 +++++++++++ spec/xml/contact_check_s.xml | 27 ++++++++++++++++++++ spec/xml/contact_info_c.xml | 15 +++++++++++ spec/xml/contact_info_s.xml | 49 ++++++++++++++++++++++++++++++++++++ 8 files changed, 175 insertions(+) create mode 100644 spec/lib/contact_spec.rb create mode 100644 spec/lib/domain_spec.rb create mode 100644 spec/spec_helper.rb create mode 100644 spec/util/test_util.rb create mode 100644 spec/xml/contact_check_c.xml create mode 100644 spec/xml/contact_check_s.xml create mode 100644 spec/xml/contact_info_c.xml create mode 100644 spec/xml/contact_info_s.xml diff --git a/spec/lib/contact_spec.rb b/spec/lib/contact_spec.rb new file mode 100644 index 0000000..21a0b51 --- /dev/null +++ b/spec/lib/contact_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe 'Contacts' do + let(:tester){ + EPPClient::Base.new( + :clTRID => 'fix', + :password => "test", + :client_id => 0, + :server => 'example.com' + ) + } + context 'check' do + it 'IETF sample' do + xml_c = readCleanXML('spec/xml/contact_check_c.xml') + xml_s = readCleanXML('spec/xml/contact_check_s.xml') + allow_message_expectations_on_nil + expect(nil).to receive(:write).with([xml_c.length+4].pack('N')+xml_c).once + expect(nil).to receive(:read).with(4).once {[xml_s.length+4].pack('N')} + expect(nil).to receive(:read).with(xml_s.length).once {xml_s} + expect(tester.contact_check :ids => ['sh8013','sah8013','8013sah']).to eq( + [{:name=>"sh8013", :avail=>true}, + {:name=>"sah8013", :avail=>false, :reason=>"In use"}, + {:name=>"8013sah", :avail=>true}]) + end + end + context 'info' do + it 'IETF sample' do + xml_c = readCleanXML('spec/xml/contact_info_c.xml') + xml_s = readCleanXML('spec/xml/contact_info_s.xml') + allow_message_expectations_on_nil + expect(nil).to receive(:write).with([xml_c.length+4].pack('N')+xml_c).once + expect(nil).to receive(:read).with(4).once {[xml_s.length+4].pack('N')} + expect(nil).to receive(:read).with(xml_s.length).once {xml_s} + expect(tester.contact_info :id => 'sh8013', :authInfo => '2fooBAR').to eq( + {:id=>"sh8013", :roid=>"SH8013-REP", :status=>["linked", "clientDeleteProhibited"], + :postalInfo=>{:int=>{:name=>"John Doe", + :addr=>{:street=>["123 Example Dr.", "Suite 100"], + :city=>"Dulles", :cc=>"US", :sp=>"VA", :pc=>"20166-6503"}, :org=>"Example Inc."}}, + #to grant compatibility create a separeted field :voice_x => "1234", + :voice=>"+1.7035555555", :fax=>"+1.7035555556", :email=>"jdoe@example.com", + :clID=>"ClientY", :crID=>"ClientX", :upID=>"ClientX", + :crDate=>DateTime.parse("1999-04-03T22:00:00Z"), + :upDate=>DateTime.parse("1999-12-03T09:00:00Z"), + :trDate=>DateTime.parse("2000-04-08T09:00:00Z"), + :authInfo=>"2fooBAR", + :disclose=>{:flag=>false, :elements=>[{:name=>"voice"}, {:name=>"email"}]}}) + end + end +end diff --git a/spec/lib/domain_spec.rb b/spec/lib/domain_spec.rb new file mode 100644 index 0000000..f8ec369 --- /dev/null +++ b/spec/lib/domain_spec.rb @@ -0,0 +1 @@ +require 'spec_helper' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..fda385a --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,3 @@ +require 'epp-client/base' +require 'util/test_util.rb' +require 'byebug' diff --git a/spec/util/test_util.rb b/spec/util/test_util.rb new file mode 100644 index 0000000..cc69d51 --- /dev/null +++ b/spec/util/test_util.rb @@ -0,0 +1,17 @@ +require 'nokogiri' + +def readXML(file) + File.read(File.expand_path(file)) +end + +def parseXML(xml) + Nokogiri::XML::Document.parse(xml,nil,nil,256) +end + +def toXML(xml) + xml.to_xml(:save_with=>Nokogiri::XML::Node::SaveOptions::AS_XML).gsub(/\sxsi:schemaLocation=\"[^\"]*\"|\sxmlns:xsi=\"[^\"]+\"|\sstandalone=\"no\"/, '').strip +end + +def readCleanXML(path) + toXML(parseXML(readXML(path))) +end diff --git a/spec/xml/contact_check_c.xml b/spec/xml/contact_check_c.xml new file mode 100644 index 0000000..685bfb7 --- /dev/null +++ b/spec/xml/contact_check_c.xml @@ -0,0 +1,14 @@ + + + + + + sh8013 + sah8013 + 8013sah + + + fix-1 + + diff --git a/spec/xml/contact_check_s.xml b/spec/xml/contact_check_s.xml new file mode 100644 index 0000000..4140b01 --- /dev/null +++ b/spec/xml/contact_check_s.xml @@ -0,0 +1,27 @@ + + + + + Command completed successfully + + + + + sh8013 + + + sah8013 + In use + + + 8013sah + + + + + ABC-12345 + 54322-XYZ + + + diff --git a/spec/xml/contact_info_c.xml b/spec/xml/contact_info_c.xml new file mode 100644 index 0000000..9f402d5 --- /dev/null +++ b/spec/xml/contact_info_c.xml @@ -0,0 +1,15 @@ + + + + + + sh8013 + + 2fooBAR + + + + fix-1 + + diff --git a/spec/xml/contact_info_s.xml b/spec/xml/contact_info_s.xml new file mode 100644 index 0000000..d07ffef --- /dev/null +++ b/spec/xml/contact_info_s.xml @@ -0,0 +1,49 @@ + + + + + Command completed successfully + + + + sh8013 + SH8013-REP + + + + John Doe + Example Inc. + + 123 Example Dr. + Suite 100 + Dulles + VA + 20166-6503 + US + + + +1.7035555555 + +1.7035555556 + jdoe@example.com + ClientY + ClientX + 1999-04-03T22:00:00.0Z + ClientX + 1999-12-03T09:00:00.0Z + 2000-04-08T09:00:00.0Z + + 2fooBAR + + + + + + + + + ABC-12345 + 54322-XYZ + + + From 375781ee69feb8e6cd72f3c8d0a0fa3fe776f045 Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Mon, 3 Nov 2014 12:54:18 -0200 Subject: [PATCH 20/29] removing authInfo from contact check --- lib/epp-client/contact.rb | 9 ++------- spec/lib/contact_spec.rb | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/epp-client/contact.rb b/lib/epp-client/contact.rb index 8fa38e2..9a20894 100644 --- a/lib/epp-client/contact.rb +++ b/lib/epp-client/contact.rb @@ -4,19 +4,14 @@ module Contact CONTACT_NS = 'contact' - def contact_check_xml(contacts) + def contact_check_xml(*contacts) command do |xml| xml.check do xml.check do xml.parent.namespace = xml.parent.add_namespace_definition(CONTACT_NS, EPPClient::SCHEMAS_URL[CONTACT_NS]) - contacts[:ids].each do |contact| + contacts.each do |contact| xml[CONTACT_NS].id contact end - if contacts.key?(:authInfo) - xml[CONTACT_NS].authInfo do - xml[CONTACT_NS].pw(contacts[:authInfo]) - end - end end end end diff --git a/spec/lib/contact_spec.rb b/spec/lib/contact_spec.rb index 21a0b51..8dcec03 100644 --- a/spec/lib/contact_spec.rb +++ b/spec/lib/contact_spec.rb @@ -17,7 +17,7 @@ expect(nil).to receive(:write).with([xml_c.length+4].pack('N')+xml_c).once expect(nil).to receive(:read).with(4).once {[xml_s.length+4].pack('N')} expect(nil).to receive(:read).with(xml_s.length).once {xml_s} - expect(tester.contact_check :ids => ['sh8013','sah8013','8013sah']).to eq( + expect(tester.contact_check ['sh8013','sah8013','8013sah']).to eq( [{:name=>"sh8013", :avail=>true}, {:name=>"sah8013", :avail=>false, :reason=>"In use"}, {:name=>"8013sah", :avail=>true}]) From 147a6c84e977a4da80501020b2b7142eb223991a Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Thu, 11 Dec 2014 15:07:29 -0200 Subject: [PATCH 21/29] changed xml size count to bitesize to support two bytes characteres --- lib/epp-client/connection.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/epp-client/connection.rb b/lib/epp-client/connection.rb index b6f8078..e8baa3e 100644 --- a/lib/epp-client/connection.rb +++ b/lib/epp-client/connection.rb @@ -54,7 +54,7 @@ def send_request(xml) # sends a frame def send_frame(xml) @sent_frame = xml - @socket.write([xml.size + 4].pack("N") + xml) + @socket.write([xml.bytesize + 4].pack("N") + xml) sent_frame_to_xml return end From eaf18fc667520deb15ddb45f12a87cde0c20b2aa Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Fri, 16 Jan 2015 14:46:57 -0200 Subject: [PATCH 22/29] added test for contact_check with single item --- spec/lib/contact_spec.rb | 9 +++++++++ spec/xml/contact_check_single_c.xml | 12 ++++++++++++ spec/xml/contact_check_single_s.xml | 20 ++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 spec/xml/contact_check_single_c.xml create mode 100644 spec/xml/contact_check_single_s.xml diff --git a/spec/lib/contact_spec.rb b/spec/lib/contact_spec.rb index 8dcec03..b45d053 100644 --- a/spec/lib/contact_spec.rb +++ b/spec/lib/contact_spec.rb @@ -22,6 +22,15 @@ {:name=>"sah8013", :avail=>false, :reason=>"In use"}, {:name=>"8013sah", :avail=>true}]) end + it 'single contatct' do + xml_c = readCleanXML('spec/xml/contact_check_single_c.xml') + xml_s = readCleanXML('spec/xml/contact_check_single_s.xml') + allow_message_expectations_on_nil + expect(nil).to receive(:write).with([xml_c.length+4].pack('N')+xml_c).once + expect(nil).to receive(:read).with(4).once {[xml_s.length+4].pack('N')} + expect(nil).to receive(:read).with(xml_s.length).once {xml_s} + expect(tester.contact_check('ABCD')).to eq([{:name=>'ABCD',:avail=>true}]) + end end context 'info' do it 'IETF sample' do diff --git a/spec/xml/contact_check_single_c.xml b/spec/xml/contact_check_single_c.xml new file mode 100644 index 0000000..f7e7ffc --- /dev/null +++ b/spec/xml/contact_check_single_c.xml @@ -0,0 +1,12 @@ + + + + + + ABCD + + + fix-1 + + diff --git a/spec/xml/contact_check_single_s.xml b/spec/xml/contact_check_single_s.xml new file mode 100644 index 0000000..b116345 --- /dev/null +++ b/spec/xml/contact_check_single_s.xml @@ -0,0 +1,20 @@ + + + + + Command completed successfully + + + + + ABCD + + + + + fix-1 + 54322-XYZ + + + From 591513249e5debbb25d663533d7a616844c4a656 Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Fri, 16 Jan 2015 14:49:12 -0200 Subject: [PATCH 23/29] set extension to return a simple xml to make compatible with tests --- lib/epp-client/xml.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/epp-client/xml.rb b/lib/epp-client/xml.rb index aba5d58..073eeea 100644 --- a/lib/epp-client/xml.rb +++ b/lib/epp-client/xml.rb @@ -149,7 +149,7 @@ def extension(&block) yield(xml) end end - ext.doc.child + ext.doc.child.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML).strip end # Insert node in root before clTRID node From 3d233862ec6d76eff837af0205e7e1ed6f65ae6c Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Fri, 16 Jan 2015 14:51:03 -0200 Subject: [PATCH 24/29] added msg_id and msg_count to the return message of poll_req --- lib/epp-client/poll.rb | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/epp-client/poll.rb b/lib/epp-client/poll.rb index 008e101..e03fc93 100644 --- a/lib/epp-client/poll.rb +++ b/lib/epp-client/poll.rb @@ -27,27 +27,30 @@ def poll_req PARSERS = {} def poll_req_process(xml) #:nodoc: - ret = {} + ret = { + :msg_id => @msgQ_id, + :msgs_count => @msgQ_count, + } if (date = xml.xpath("epp:msgQ/epp:qDate", EPPClient::SCHEMAS_URL)).size > 0 - ret[:qDate] = DateTime.parse(date.text) + ret[:qDate] = DateTime.parse(date.text) end if (msg = xml.xpath("epp:msgQ/epp:msg", EPPClient::SCHEMAS_URL)).size > 0 - ret[:msg] = msg.text - ret[:msg_xml] = msg.to_s + ret[:msg] = msg.text + ret[:msg_xml] = msg.to_s end if (obj = xml.xpath('epp:resData', EPPClient::SCHEMAS_URL)).size > 0 || - (obj = xml.xpath('epp:extension', EPPClient::SCHEMAS_URL)).size > 0 - ret[:obj_xml] = obj.to_s - PARSERS.each do |xpath,parser| - if obj.xpath(xpath, EPPClient::SCHEMAS_URL).size > 0 - ret[:obj] = case parser - when Symbol - send(parser, xml) - else - raise NotImplementedError - end - end - end + (obj = xml.xpath('epp:extension', EPPClient::SCHEMAS_URL)).size > 0 + ret[:obj_xml] = obj.to_s + PARSERS.each do |xpath,parser| + if obj.xpath(xpath, EPPClient::SCHEMAS_URL).size > 0 + ret[:obj] = case parser + when Symbol + send(parser, xml) + else + raise NotImplementedError + end + end + end end ret end From 84bead33ec0d7b5de22e4731235f0d968e8fdc18 Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Fri, 16 Jan 2015 14:58:55 -0200 Subject: [PATCH 25/29] Removed builder requirement. Moved RGP schema to it's Module --- lib/epp-client/base.rb | 10 +--------- lib/epp-client/rgp.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/epp-client/base.rb b/lib/epp-client/base.rb index 8662281..3cc0f46 100644 --- a/lib/epp-client/base.rb +++ b/lib/epp-client/base.rb @@ -1,7 +1,6 @@ require 'openssl' require 'socket' require 'nokogiri' -require 'builder' require 'date' require "epp-client/version" require 'epp-client/xml' @@ -22,19 +21,12 @@ class Base host-1.0 contact-1.0 ] - SCHEMAS_EXT_IETF = %w[ - rgp-1.0 - ] EPPClient::SCHEMAS_URL = SCHEMAS.inject({}) do |a,s| a[s.sub(/-1\.0$/, '')] = "urn:ietf:params:xml:ns:#{s}" if s =~ /-1\.0$/ a[s] = "urn:ietf:params:xml:ns:#{s}" a - end.merge!(SCHEMAS_EXT_IETF.inject({}) do |a,s| - a[s.sub(/-1\.0$/, '')] = "urn:ietf:params:xml:ns:#{s}" if s =~ /-1\.0$/ - a[s] = "urn:ietf:params:xml:ns:#{s}" - a - end) + end include EPPClient::XML include EPPClient::Session diff --git a/lib/epp-client/rgp.rb b/lib/epp-client/rgp.rb index 342d83e..cffbd26 100644 --- a/lib/epp-client/rgp.rb +++ b/lib/epp-client/rgp.rb @@ -7,6 +7,17 @@ module EPPClient # Has to be included after the initialize, domain_info and domain_update # definitions. module RGP + + SCHEMAS_EXT_IETF = %w[ + rgp-1.0 + ] + + EPPClient::SCHEMAS_URL.merge!(SCHEMAS_EXT_IETF.inject({}) do |a,s| + a[s.sub(/-1\.0$/, '')] = "urn:ietf:params:xml:ns:#{s}" if s =~ /-1\.0$/ + a[s] = "urn:ietf:params:xml:ns:#{s}" + a + end) + def initialize(args) #:nodoc: super @extensions << EPPClient::SCHEMAS_URL['rgp'] From 4d56bd03c6000c30a7e0f6f905379e59fc06852e Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Fri, 16 Jan 2015 15:00:15 -0200 Subject: [PATCH 26/29] removed wrong sintax --- lib/epp-client/contact.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/epp-client/contact.rb b/lib/epp-client/contact.rb index 9a20894..ebd2a23 100644 --- a/lib/epp-client/contact.rb +++ b/lib/epp-client/contact.rb @@ -4,7 +4,7 @@ module Contact CONTACT_NS = 'contact' - def contact_check_xml(*contacts) + def contact_check_xml(contacts) command do |xml| xml.check do xml.check do @@ -31,7 +31,7 @@ def contact_check_xml(*contacts) def contact_check(*contacts) contacts.flatten! - response = send_request(contact_check_xml(*contacts)) + response = send_request(contact_check_xml(contacts)) get_result(:xml => response, :callback => :contact_check_process) end From bc57b17a8eb1b3ceee8bb3429ca1c7cf29725e3f Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Fri, 16 Jan 2015 15:01:56 -0200 Subject: [PATCH 27/29] Fixed some missing namespace definitions. Added domin renew function --- lib/epp-client/domain.rb | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/epp-client/domain.rb b/lib/epp-client/domain.rb index 3ca0d60..1e9cc33 100644 --- a/lib/epp-client/domain.rb +++ b/lib/epp-client/domain.rb @@ -229,7 +229,7 @@ def domain_create_xml(args) #:nodoc: if args.key?(:ns) domain_nss_xml(xml, args[:ns]) end - xml.registrant args[:registrant] if args.key?(:registrant) + xml[DOMAIN_NS].registrant args[:registrant] if args.key?(:registrant) if args.key?(:contacts) domain_contacts_xml(xml, args[:contacts]) end @@ -337,7 +337,7 @@ def domain_update_xml(args) #:nodoc: end end if args.key?(:chg) && (args[:chg].key?(:registrant) || args[:chg].key?(:authInfo)) - xml.chg do + xml[DOMAIN_NS].chg do if args[:chg].key?(:registrant) xml[DOMAIN_NS].registrant args[:chg][:registrant] end @@ -414,5 +414,36 @@ def domain_transfer_response(xml) #:nodoc: end ret end + + def domain_renew(args) + response = send_request(domain_renew_xml(args)) + + get_result(:xml => response, :callback => :domain_renew_process) + end + + def domain_renew_xml(args) + command do |xml| + xml.renew do + xml.renew do + xml.parent.namespace = xml.parent.add_namespace_definition(DOMAIN_NS, EPPClient::SCHEMAS_URL[DOMAIN_NS]) + xml[DOMAIN_NS].name args[:name] + xml[DOMAIN_NS].curExpDate args[:curExpDate] + if args.key?(:period) + xml[DOMAIN_NS].period({:unit => args[:period][:unit]}, args[:period][:value]) + end + end + end + end + end + + def domain_renew_process(xml) + dom = xml.xpath('//domain:renData', EPPClient::SCHEMAS_URL).children + res = {:name => dom.xpath('//domain:name', EPPClient::SCHEMAS_URL).text} + unless (result = dom.xpath('//domain:exDate', EPPClient::SCHEMAS_URL).text).empty? + res[:exDate] = DateTime.parse(result) + end + res + end + end end From 3f26b6886414e77a20fd96410cd1bbfb1fa4421c Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Fri, 16 Jan 2015 15:02:52 -0200 Subject: [PATCH 28/29] Moved to new gem file --- epp-client-base.gemspec | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/epp-client-base.gemspec b/epp-client-base.gemspec index e311527..20d2d3b 100644 --- a/epp-client-base.gemspec +++ b/epp-client-base.gemspec @@ -2,16 +2,15 @@ require File.expand_path('../lib/epp-client/version', __FILE__) Gem::Specification.new do |gem| - gem.name = 'epp-client-base' + gem.name = 'globo-epp-client' gem.version = EPPClient::VERSION - gem.authors = ['Mathieu Arnold'] - gem.email = ['m@absolight.fr'] + gem.authors = ['Ernesto Thorp'] + gem.email = ['ernestothorp@gmail.com'] gem.description = 'An extensible EPP client library.' - gem.summary = 'An extensible EPP client library' - gem.homepage = "https://github.com/Absolight/epp-client" - - gem.required_ruby_version = '>= 1.8.7' - gem.required_rubygems_version = ">= 1.3.6" + gem.summary = 'An extensible EPP client library based on https://github.com/Absolight/epp-client' + gem.homepage = "https://github.com/ernestothorp/epp-client" + gem.required_ruby_version = '>= 2.0.0' + gem.required_rubygems_version = ">= 2.0.0" gem.files = [ 'ChangeLog', @@ -47,8 +46,9 @@ Gem::Specification.new do |gem| gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") gem.require_paths = ['lib'] - gem.add_development_dependency 'bundler', '>= 1.0.0' - gem.add_dependency('nokogiri', '~> 1.4') - gem.add_dependency('builder', '>= 2.1.2') + gem.add_development_dependency "bundler", "~> 1.6" + gem.add_development_dependency "rake" gem.add_development_dependency 'rspec' + + gem.add_dependency('nokogiri', '~> 1.4') end From 1e588bd5dfd15aaadebc26c927814945db931b4c Mon Sep 17 00:00:00 2001 From: Ernesto Thorp Date: Fri, 16 Jan 2015 15:03:34 -0200 Subject: [PATCH 29/29] bump to version 1.0.3 --- lib/epp-client/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/epp-client/version.rb b/lib/epp-client/version.rb index 526ba3d..1769ff6 100644 --- a/lib/epp-client/version.rb +++ b/lib/epp-client/version.rb @@ -1,3 +1,3 @@ module EPPClient - VERSION = "0.13.3" + VERSION = "1.0.3" end