Skip to content

Commit

Permalink
Merge pull request #4 from charrisbc/update-expired
Browse files Browse the repository at this point in the history
Adds support for renewing expired domains:
  • Loading branch information
charrisbc committed Feb 18, 2016
2 parents 125018d + 5f9c122 commit 5e80143
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lib/enom/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def self.register!(name, options = {})
sld, tld = parse_sld_and_tld(name)
opts = {}
options = options.dup

if options[:nameservers]
count = 1
options.delete(:nameservers).each do |nameserver|
Expand All @@ -120,7 +120,7 @@ def self.register!(name, options = {})

opts.merge!("NumYears" => options.delete(:years)) if options[:years]
opts.merge!(options)

response = Client.request({"Command" => "Purchase", "SLD" => sld, "TLD" => tld}.merge(opts))
Domain.find(name)
end
Expand Down Expand Up @@ -167,6 +167,26 @@ def self.renew!(name, options = {})
opts.merge!("NumYears" => options[:years]) if options[:years]
response = Client.request({"Command" => "Extend", "SLD" => sld, "TLD" => tld}.merge(opts))
Domain.find(name)
end

# Renew a domain that has already expired
def self.update_expired!(name, years = 1)
unless valid_renewal_length?(years)
raise ArgumentError, "Renewal years must be an integer between 1 and 10!"
end

request_params = {
"Command" => "UpdateExpiredDomains",
"DomainName" => name,
"NumYears" => years
}

response = Client.request(request_params)
response['interface_response']['ErrCount'] == "0" ? Domain.find(name) : false
end

def self.valid_renewal_length?(years)
years >= 1 && years <= 10
end

# Suggest available domains using the namespinner
Expand Down
9 changes: 9 additions & 0 deletions test/domain_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ class DomainTest < Test::Unit::TestCase
end
end

context "renewing an expired domain" do
setup do
@domain = Enom::Domain.update_expired!("test123456test123456.com")
end
should "renew the domain and return a domain object" do
assert_equal @domain.name, "test123456test123456.com"
end
end

context "finding a domain in your account" do
setup do
@domain = Enom::Domain.find("test123456test123456.com")
Expand Down
28 changes: 28 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,34 @@ class Test::Unit::TestCase
<debug><![CDATA[ ]]></debug>
</interface-response>
EOF
},{
command: "UpdateExpiredDomains",
request: "https://reseller.enom.com/interface.asp?Command=UpdateExpiredDomains&DomainName=test123456test123456.com&NumYears=1&UID=resellid&PW=resellpw&ResponseType=xml",
response: <<-EOF
<?xml version="1.0" ?>
<interface-response>
<ReactivateDomainName>
<Status>True</Status>
<OrderID>157614452</OrderID>
</ReactivateDomainName>
<Command>UPDATEEXPIREDDOMAINS</Command>
<Language>eng</Language>
<ErrCount>0</ErrCount>
<ResponseCount>0</ResponseCount>
<MinPeriod>1</MinPeriod>
<MaxPeriod>10</MaxPeriod>
<Server>RESELLERTEST</Server>
<Site>enom</Site>
<IsLockable>True</IsLockable>
<IsRealTimeTLD>True</IsRealTimeTLD>
<TimeDifference>+08.00</TimeDifference>
<ExecTime>0.938</ExecTime>
<Done>true</Done>
<debug>
<![CDATA[ ]]>
</debug>
</interface-response>
EOF
}

]
Expand Down

0 comments on commit 5e80143

Please sign in to comment.