Class: Enom::Domain

Inherits:
Object
  • Object
show all
Includes:
ContactInfo, HTTParty
Defined in:
lib/enom/domain.rb

Constant Summary

Constants included from ContactInfo

ContactInfo::CONTACT_TYPES, ContactInfo::FIELDS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Domain

Returns a new instance of Domain.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/enom/domain.rb', line 17

def initialize(attributes)
  @name = attributes["DomainName"] || attributes["domainname"]
  @sld, @tld = @name.split('.')

  expiration_date_string = attributes["expiration_date"] || attributes["status"]["expiration"]
  @expiration_date = Date.strptime(expiration_date_string.split(' ').first, "%m/%d/%Y")

  # If we have more attributes for the domain from running GetDomainInfo
  # (as opposed to GetAllDomains), we should save it to the instance to
  # save on future API calls
  if attributes["services"] && attributes["status"]
    set_extended_domain_attributes(attributes)
  end
end

Instance Attribute Details

#expiration_dateObject (readonly)

Domain expiration date (currently returns a string - 11/9/2010 11:57:39 AM)



14
15
16
# File 'lib/enom/domain.rb', line 14

def expiration_date
  @expiration_date
end

#nameObject (readonly)

The domain name on Enom



8
9
10
# File 'lib/enom/domain.rb', line 8

def name
  @name
end

#sldObject (readonly)

Second-level and first-level domain on Enom



11
12
13
# File 'lib/enom/domain.rb', line 11

def sld
  @sld
end

#tldObject (readonly)

Second-level and first-level domain on Enom



11
12
13
# File 'lib/enom/domain.rb', line 11

def tld
  @tld
end

Class Method Details

.all(options = {}) ⇒ Object

Find and return all domains in the account



52
53
54
55
56
57
58
# File 'lib/enom/domain.rb', line 52

def self.all(options = {})
  response = Client.request("Command" => "GetAllDomains")["interface_response"]["GetAllDomains"]["DomainDetail"]

  domains = []
  response.each {|d| domains << Domain.new(d) }
  return domains
end

.check(name) ⇒ Object

Determine if the domain is available for purchase



40
41
42
43
44
45
46
47
48
49
# File 'lib/enom/domain.rb', line 40

def self.check(name)
  sld, tld = name.split('.')
  response = Client.request("Command" => "Check", "SLD" => sld, "TLD" => tld)["interface_response"]["RRPCode"]

  if response == "210"
    "available"
  else
    "unavailable"
  end
end

.find(name) ⇒ Object

Find the domain (must be in your account) on Enom



33
34
35
36
37
# File 'lib/enom/domain.rb', line 33

def self.find(name)
  sld, tld = name.split('.')
  response = Client.request('Command' => 'GetDomainInfo', 'SLD' => sld, 'TLD' => tld)["interface_response"]["GetDomainInfo"]
  Domain.new(response)
end

.register!(name, options = {}) ⇒ Object

Purchase the domain



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/enom/domain.rb', line 61

def self.register!(name, options = {})
  sld, tld = name.split('.')
  opts = {}
  if options[:nameservers]
    count = 1
    options[:nameservers].each do |nameserver|
      opts.merge!("NS#{count}" => nameserver)
      count += 1
    end
  else
    opts.merge!("UseDNS" => "default")
  end
  opts.merge!('NumYears' => options[:years]) if options[:years]
  response = Client.request({'Command' => 'Purchase', 'SLD' => sld, 'TLD' => tld}.merge(opts))
  Domain.find(name)
end

.renew!(name, options = {}) ⇒ Object

Renew the domain



79
80
81
82
83
84
85
# File 'lib/enom/domain.rb', line 79

def self.renew!(name, options = {})
  sld, tld = name.split('.')
  opts = {}
  opts.merge!('NumYears' => options[:years]) if options[:years]
  response = Client.request({'Command' => 'Extend', 'SLD' => sld, 'TLD' => tld}.merge(opts))
  Domain.find(name)
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


152
153
154
# File 'lib/enom/domain.rb', line 152

def active?
  registration_status == "Registered"
end

#expired?Boolean

Returns:

  • (Boolean)


156
157
158
# File 'lib/enom/domain.rb', line 156

def expired?
  registration_status == "Expired"
end

#lockObject

Lock the domain at the registrar so it can’t be transferred



88
89
90
91
92
# File 'lib/enom/domain.rb', line 88

def lock
  Client.request('Command' => 'SetRegLock', 'SLD' => sld, 'TLD' => tld, 'UnlockRegistrar' => '0')
  @locked = true
  return self
end

#lockedObject Also known as: locked?

Check if the domain is currently locked. locked? helper method also available



102
103
104
105
106
107
108
# File 'lib/enom/domain.rb', line 102

def locked
  unless defined?(@locked)
    response = Client.request('Command' => 'GetRegLock', 'SLD' => sld, 'TLD' => tld)['interface_response']['reg_lock']
    @locked = response == '1'
  end
  return @locked
end

#nameserversObject

Return the DNS nameservers that are currently used for the domain



118
119
120
121
# File 'lib/enom/domain.rb', line 118

def nameservers
  get_extended_domain_attributes unless @nameservers
  return @nameservers
end

#registration_statusObject



147
148
149
150
# File 'lib/enom/domain.rb', line 147

def registration_status
  get_extended_domain_attributes unless @registration_status
  return @registration_status
end

#renew!(options = {}) ⇒ Object



160
161
162
# File 'lib/enom/domain.rb', line 160

def renew!(options = {})
  Domain.renew!(name, options)
end

#unlockObject

Unlock the domain at the registrar to permit transfers



95
96
97
98
99
# File 'lib/enom/domain.rb', line 95

def unlock
  Client.request('Command' => 'SetRegLock', 'SLD' => sld, 'TLD' => tld, 'UnlockRegistrar' => '1')
  @locked = false
  return self
end

#unlockedObject Also known as: unlocked?

Check if the domain is currently unlocked. unlocked? helper method also available



112
113
114
# File 'lib/enom/domain.rb', line 112

def unlocked
  !locked?
end

#update_nameservers(nameservers = []) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/enom/domain.rb', line 123

def update_nameservers(nameservers = [])
  count = 1
  ns = {}
  if (2..12).include?(nameservers.size)
    nameservers.each do |nameserver|
      ns.merge!("NS#{count}" => nameserver)
      count += 1
    end
    Client.request({'Command' => 'ModifyNS', 'SLD' => sld, 'TLD' => tld}.merge(ns))
    @nameservers = ns.values
    return self
  else
    raise InvalidNameServerCount
  end
end