Skip to content

Commit

Permalink
Merge pull request #3 from splittingred/autorenew
Browse files Browse the repository at this point in the history
Add ability to retrieve and set auto-renew status for a Domain
  • Loading branch information
splittingred committed Apr 14, 2015
2 parents a594591 + 263b8fc commit 125018d
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 1 deletion.
2 changes: 1 addition & 1 deletion enom.gemspec
Original file line number Diff line number Diff line change
@@ -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.}
Expand Down
37 changes: 37 additions & 0 deletions lib/enom/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -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
20 changes: 20 additions & 0 deletions test/domain_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
96 changes: 96 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,102 @@ class Test::Unit::TestCase
<debug><![CDATA[ ]]></debug>
</interface-response>
EOF
},{
command: "GetRenew",
request: "https://reseller.enom.com/interface.asp?Command=GetRenew&SLD=test123456test123456&TLD=com&UID=resellid&PW=resellpw&ResponseType=xml",
response: <<-EOF
<?xml version="1.0" encoding="UTF-8"?>
<interface-response>
<auto-renew>0</auto-renew>
<AutoPakRenew>0</AutoPakRenew>
<PakExist>0</PakExist>
<EmailForwardRenew>0</EmailForwardRenew>
<EmailFwdExists>0</EmailFwdExists>
<URLForwardRenew>0</URLForwardRenew>
<URLFwdExists>0</URLFwdExists>
<IDProtectRenew>0</IDProtectRenew>
<IDProtectExists>0</IDProtectExists>
<MobilizerRenew>0</MobilizerRenew>
<Command>GETRENEW</Command>
<APIType>API.NET</APIType>
<Language>eng</Language>
<ErrCount>0</ErrCount>
<ResponseCount>0</ResponseCount>
<MinPeriod>1</MinPeriod>
<MaxPeriod>10</MaxPeriod>
<Server>RESELLER1-STG</Server>
<Site>eNom</Site>
<IsRealTimeTLD>True</IsRealTimeTLD>
<TimeDifference>+03.00</TimeDifference>
<ExecTime>1.715</ExecTime>
<Done>true</Done>
<debug><![CDATA[ ]]></debug>
</interface-response>
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
<?xml version="1.0" encoding="UTF-8"?>
<interface-response>
<RenewName>1</RenewName>
<AutoPakRenew>0</AutoPakRenew>
<PakExist>0</PakExist>
<EmailForwardRenew>0</EmailForwardRenew>
<EmailFwdExists>0</EmailFwdExists>
<URLForwardRenew>0</URLForwardRenew>
<URLFwdExists>0</URLFwdExists>
<IDProtectRenew>0</IDProtectRenew>
<IDProtectExists>0</IDProtectExists>
<MobilizerRenew>0</MobilizerRenew>
<Command>GETRENEW</Command>
<APIType>API.NET</APIType>
<Language>eng</Language>
<ErrCount>0</ErrCount>
<ResponseCount>0</ResponseCount>
<MinPeriod>1</MinPeriod>
<MaxPeriod>10</MaxPeriod>
<Server>RESELLER1-STG</Server>
<Site>eNom</Site>
<IsRealTimeTLD>True</IsRealTimeTLD>
<TimeDifference>+03.00</TimeDifference>
<ExecTime>1.715</ExecTime>
<Done>true</Done>
<debug><![CDATA[ ]]></debug>
</interface-response>
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
<?xml version="1.0" encoding="UTF-8"?>
<interface-response>
<auto_renew>0</auto_renew>
<AutoPakRenew>0</AutoPakRenew>
<PakExist>0</PakExist>
<EmailForwardRenew>0</EmailForwardRenew>
<EmailFwdExists>0</EmailFwdExists>
<URLForwardRenew>0</URLForwardRenew>
<URLFwdExists>0</URLFwdExists>
<IDProtectRenew>0</IDProtectRenew>
<IDProtectExists>0</IDProtectExists>
<MobilizerRenew>0</MobilizerRenew>
<Command>GETRENEW</Command>
<APIType>API.NET</APIType>
<Language>eng</Language>
<ErrCount>0</ErrCount>
<ResponseCount>0</ResponseCount>
<MinPeriod>1</MinPeriod>
<MaxPeriod>10</MaxPeriod>
<Server>RESELLER1-STG</Server>
<Site>eNom</Site>
<IsRealTimeTLD>True</IsRealTimeTLD>
<TimeDifference>+03.00</TimeDifference>
<ExecTime>1.715</ExecTime>
<Done>true</Done>
<debug><![CDATA[ ]]></debug>
</interface-response>
EOF
}

]
Expand Down

0 comments on commit 125018d

Please sign in to comment.