Skip to content

Commit

Permalink
Merge pull request #8 from billthompson/brp-5181
Browse files Browse the repository at this point in the history
Domain renew ensures the expiration date is the date from the renew response
  • Loading branch information
billthompson committed Feb 17, 2017
2 parents be47bc3 + 217c1dc commit e4efcfb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 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.7"
s.version = "1.1.8"
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 All @@ -10,6 +10,7 @@ Gem::Specification.new do |s|
s.has_rdoc = false
s.add_dependency "httparty", "~> 0.10.0"
s.add_dependency "public_suffix", "~> 1.5.3"
s.add_dependency "activesupport", "> 4.2"
s.add_development_dependency "test-unit"
s.add_development_dependency "shoulda"
s.add_development_dependency "fakeweb"
Expand Down
17 changes: 14 additions & 3 deletions lib/enom/domain.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'active_support'
require 'active_support/core_ext/object/blank'
require "public_suffix"

module Enom
Expand Down Expand Up @@ -175,9 +177,14 @@ def self.renew!(name, options = {})
sld, tld = parse_sld_and_tld(name)
opts = {}
opts.merge!("NumYears" => options[:years]) if options[:years]
response = Client.request({"Command" => "Extend", "SLD" => sld, "TLD" => tld}.merge(opts))
Domain.find(name)
end
renew_response = Client.request({"Command" => "Extend", "SLD" => sld, "TLD" => tld}.merge(opts))
domain = Domain.find(name)
# Enom doesn't make the new registration date immediately available in the find request, so we patch that
# value into the object.
registry_exp_date = renew_response.parsed_response['interface_response']['DomainInfo']['RegistryExpDate']
domain.expiration_date = Date.strptime(registry_exp_date.split(" ").first, '%Y-%m-%d')
domain
end

# Renew a domain that has already expired
def self.update_expired!(name, years = 1)
Expand Down Expand Up @@ -326,6 +333,10 @@ def expiration_date
@expiration_date
end

def expiration_date=(date)
@expiration_date = date
end

def registration_status
get_extended_domain_attributes unless @registration_status
return @registration_status
Expand Down
5 changes: 5 additions & 0 deletions test/domain_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ class DomainTest < Test::Unit::TestCase
assert_kind_of Enom::Domain, @domain
assert_equal @domain.name, "test123456test123456.com"
end

should "return the domain reflecting the new expiration date" do
original_expiration_date = Enom::Domain.find('test123456test123456.com').expiration_date
assert_true (@domain.expiration_date - original_expiration_date).to_i > 365
end
end

context "renewing an expired domain" do
Expand Down
3 changes: 3 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,9 @@ class Test::Unit::TestCase
<interface-response>
<Extension>successful</Extension>
<DomainName>test123456test123456.com</DomainName>
<DomainInfo>
<RegistryExpDate>2013-01-30 19:07:50.000</RegistryExpDate>
</DomainInfo>
<OrderID>157609742</OrderID>
<RRPCode>200</RRPCode>
<RRPText>Command completed successfully</RRPText>
Expand Down

0 comments on commit e4efcfb

Please sign in to comment.