Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Domain update_expired returns the domain's correct expiration date and status #9

Merged
merged 1 commit into from
Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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