From 263b8fc952f3138231600c6c3e1094aa20bc800c Mon Sep 17 00:00:00 2001 From: Shaun McCormick Date: Tue, 14 Apr 2015 08:54:06 -0500 Subject: [PATCH] Add ability to retrieve and set auto-renew status for a Domain --- enom.gemspec | 2 +- lib/enom/domain.rb | 37 +++++++++++++++++ test/domain_test.rb | 20 ++++++++++ test/test_helper.rb | 96 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 154 insertions(+), 1 deletion(-) diff --git a/enom.gemspec b/enom.gemspec index 68ea5dc..2b58da7 100644 --- a/enom.gemspec +++ b/enom.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "enom" - s.version = "1.1.3" + s.version = "1.1.4" s.authors = ["James Miller"] s.summary = %q{Ruby wrapper for the Enom API} s.description = %q{Enom is a Ruby wrapper and command line interface for portions of the Enom domain reseller API.} diff --git a/lib/enom/domain.rb b/lib/enom/domain.rb index 34bbaac..ebd809f 100644 --- a/lib/enom/domain.rb +++ b/lib/enom/domain.rb @@ -206,6 +206,34 @@ def unlock return self end + ## + # Get auto-renew state of Domain + # + # @return [Boolean] + # + def auto_renew? + unless defined?(@auto_renew) + response = Client.request('Command' => 'GetRenew', 'SLD' => sld, 'TLD' => tld) + validate_response!(response) + @auto_renew = response['interface_response']['auto_renew'].to_i + end + @auto_renew + end + alias_method :auto_renew, :auto_renew? + + ## + # Set auto-renew state for the domain + # + # @param [Boolean|Integer] auto_renew + # @return [Enom::Domain] + # + def auto_renew=(auto_renew) + response = Client.request('Command' => 'SetRenew', 'SLD' => sld, 'TLD' => tld, 'RenewFlag' => auto_renew) + validate_response!(response) + @auto_renew = auto_renew == 1 + self + end + # # synchronize EPP key with Registry, and optionally email it to owner # @@ -302,5 +330,14 @@ def set_extended_domain_attributes(attributes) return self end + ## + # Validate the response from Enom + # + # @raise [Enom::InterfaceError] If response is invalid + def validate_response!(response) + unless response.is_a?(Hash) && response.key?('interface_response') + raise Enom::InterfaceError, response.inspect + end + end end end diff --git a/test/domain_test.rb b/test/domain_test.rb index 4424fb6..d5e55bb 100644 --- a/test/domain_test.rb +++ b/test/domain_test.rb @@ -245,6 +245,26 @@ class DomainTest < Test::Unit::TestCase assert @domain.unlocked? end end + + context 'that is currently set to auto-renew' do + setup do + @domain.auto_renew = 1 + end + + should 'return proper auto_renew state' do + assert @domain.auto_renew? + end + end + + context 'that is currently set to not auto-renew' do + setup do + @domain.auto_renew = 0 + end + + should 'return proper auto_renew state' do + assert !@domain.auto_renew? + end + end end context "finding the latest tlds in your account" do diff --git a/test/test_helper.rb b/test/test_helper.rb index 0f6904e..e18711c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -754,6 +754,102 @@ class Test::Unit::TestCase EOF + },{ + command: "GetRenew", + request: "https://reseller.enom.com/interface.asp?Command=GetRenew&SLD=test123456test123456&TLD=com&UID=resellid&PW=resellpw&ResponseType=xml", + response: <<-EOF + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + GETRENEW + API.NET + eng + 0 + 0 + 1 + 10 + RESELLER1-STG + eNom + True + +03.00 + 1.715 + true + + + EOF + },{ + command: "SetRenew", + request: "https://reseller.enom.com/interface.asp?Command=SetRenew&SLD=test123456test123456&TLD=com&RenewFlag=1&UID=resellid&PW=resellpw&ResponseType=xml", + response: <<-EOF + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + GETRENEW + API.NET + eng + 0 + 0 + 1 + 10 + RESELLER1-STG + eNom + True + +03.00 + 1.715 + true + + + EOF + },{ + command: "SetRenew", + request: "https://reseller.enom.com/interface.asp?Command=SetRenew&SLD=test123456test123456&TLD=com&RenewFlag=0&UID=resellid&PW=resellpw&ResponseType=xml", + response: <<-EOF + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + GETRENEW + API.NET + eng + 0 + 0 + 1 + 10 + RESELLER1-STG + eNom + True + +03.00 + 1.715 + true + + + EOF } ]