Skip to content

Commit

Permalink
Merge pull request #9 from billthompson/brp-5181
Browse files Browse the repository at this point in the history
Domain update_expired returns the domain's correct expiration date and status
  • Loading branch information
billthompson committed Feb 17, 2017
2 parents e4efcfb + 6437845 commit 5893d6f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
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.8"
s.version = "1.1.9"
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
22 changes: 21 additions & 1 deletion lib/enom/domain.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'active_support'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/date/calculations'
require "public_suffix"

module Enom
Expand Down Expand Up @@ -199,7 +200,22 @@ def self.update_expired!(name, years = 1)
}

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

domain = Domain.find(name)
# Enom doesn't make the new registration date and status immediately available in the find request, so
# we patch that value into the object if necessary.
if (domain.expiration_date < Date.today)
domain.expiration_date = domain.expiration_date.advance(years: years)
end

if (domain.registration_status == "Expired")
domain.registration_status = "Registered"
end

domain
end

def self.valid_renewal_length?(years)
Expand Down Expand Up @@ -342,6 +358,10 @@ def registration_status
return @registration_status
end

def registration_status=(status)
@registration_status = status
end

def active?
registration_status == "Registered"
end
Expand Down
9 changes: 9 additions & 0 deletions test/domain_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ class DomainTest < Test::Unit::TestCase
should "renew the domain and return a domain object" do
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_equal @domain.expiration_date, original_expiration_date.advance(years: 1)
end

should "return the domain reflecting the new regisration status" do
assert_true @domain.registration_status == "Registered"
end
end

context "finding a domain in your account" do
Expand Down

0 comments on commit 5893d6f

Please sign in to comment.