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.



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

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

  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)



16
17
18
# File 'lib/enom/domain.rb', line 16

def expiration_date
  @expiration_date
end

#nameObject (readonly)

The domain name on Enom



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

def name
  @name
end

#sldObject (readonly)

Second-level and first-level domain on Enom



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

def sld
  @sld
end

#tldObject (readonly)

Second-level and first-level domain on Enom



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

def tld
  @tld
end

Class Method Details

.all(options = {}) ⇒ Object

Find and return all domains in the account



89
90
91
92
93
94
95
# File 'lib/enom/domain.rb', line 89

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

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

.available?(name) ⇒ Boolean

Boolean helper method to determine if the domain is available for purchase

Returns:

  • (Boolean)


47
48
49
50
51
# File 'lib/enom/domain.rb', line 47

def self.available?(name)
  sld, tld = parse_sld_and_tld(name)
  response = Client.request("Command" => "Check", "SLD" => sld, "TLD" => tld)["interface_response"]["RRPCode"]
  response == "210"
end

.check(name) ⇒ Object

Determine if the domain is available for purchase



42
43
44
# File 'lib/enom/domain.rb', line 42

def self.check(name)
  available?(name) ? "available" : "unavailable"
end

.check_multiple_tlds(sld, tlds = "*") ⇒ Object

You can provide one of the default check lists or provide an array of strings to check a custom set of TLDs. Enom currently chokes when specifying a custom list, so this will raise a NotImplementedError until Enom fixes this



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/enom/domain.rb', line 65

def self.check_multiple_tlds(sld, tlds = "*")
  if tlds.kind_of?(Array)
    # list = tlds.join(",")
    # tld  = nil
    raise NotImplementedError
  elsif %w(* *1 *2 @).include?(tlds)
    list = nil
    tld  = tlds
  end

  response = Client.request("Command" => "Check", "SLD" => sld, "TLD" => tld, "TLDList" => list)

  result = []
  response["interface_response"].each do |k, v|
    if v == "210" #&& k[0,6] == "RRPCode"
      pos = k[7..k.size]
      result << response["interface_response"]["Domain#{pos}"] unless k.nil? || k.empty?
    end
  end

  return result
end

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

Delete a domain name registration from your account. The domain must be less than 5 days old and you must be on Enom’s “DeleteRegistration whitelist” for resellers (your account rep can enable it for you).

Returns true if successful, false if failed.



120
121
122
123
124
125
# File 'lib/enom/domain.rb', line 120

def self.delete!(name, options = {})
  sld, tld = parse_sld_and_tld(name)

  response = Client.request({'Command' => 'DeleteRegistration', 'SLD' => sld, 'TLD' => tld}.merge(options))['interface_response']
  response['RRPCode'].to_i == 200
end

.find(name) ⇒ Object

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



35
36
37
38
39
# File 'lib/enom/domain.rb', line 35

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

.parse_sld_and_tld(domain_name) ⇒ Object

Parse out domain name tld and sld from the PublicSuffix lib



177
178
179
180
# File 'lib/enom/domain.rb', line 177

def self.parse_sld_and_tld(domain_name)
  d = PublicSuffix.parse(domain_name)
  [d.sld, d.tld]
end

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

Purchase the domain



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/enom/domain.rb', line 98

def self.register!(name, options = {})
  sld, tld = parse_sld_and_tld(name)
  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



151
152
153
154
155
156
157
# File 'lib/enom/domain.rb', line 151

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

.suggest(name, options = {}) ⇒ Object

Suggest available domains using the namespinner Returns an array of available domain names that match



161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/enom/domain.rb', line 161

def self.suggest(name, options ={})
  sld, tld = parse_sld_and_tld(name)
  opts = {}
  opts.merge!("MaxResults" => options[:max_results] || 8, "Similar" => options[:similar] || "High")
  response = Client.request({"Command" => "namespinner", "SLD" => sld, "TLD" => tld}.merge(opts))

  suggestions = []
  response["interface_response"]["namespin"]["domains"]["domain"].map do |d|
    (options[:tlds] || %w(com net tv cc)).each do |toplevel|
      suggestions << [d["name"].downcase, toplevel].join(".") if d[toplevel] == "y"
    end
  end
  return suggestions
end

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

Transfer domain from another registrar to Enom, charges the account when successful Returns true if successful, false if failed



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/enom/domain.rb', line 129

def self.transfer!(name, auth, options = {})
  sld, tld = parse_sld_and_tld(name)

  # Default options
  opts = {
    "OrderType"   => "AutoVerification",
    "DomainCount" => 1,
    "SLD1"        => sld,
    "TLD1"        => tld,
    "AuthInfo1"   => auth, # Authorization (EPP) key from the
    "UseContacts" => 1     # Set UseContacts=1 to transfer existing Whois contacts with a domain that does not require extended attributes.
  }

  opts.merge!("Renew" => 1) if options[:renew]

  response = Client.request({"Command" => "TP_CreateOrder"}.merge(opts))["ErrCount"]

  response.to_i == 0
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


247
248
249
# File 'lib/enom/domain.rb', line 247

def active?
  registration_status == "Registered"
end

#expired?Boolean

Returns:

  • (Boolean)


251
252
253
# File 'lib/enom/domain.rb', line 251

def expired?
  registration_status == "Expired"
end

#lockObject

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



183
184
185
186
187
# File 'lib/enom/domain.rb', line 183

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



197
198
199
200
201
202
203
# File 'lib/enom/domain.rb', line 197

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



213
214
215
216
# File 'lib/enom/domain.rb', line 213

def nameservers
  get_extended_domain_attributes unless @nameservers
  return @nameservers
end

#registration_statusObject



242
243
244
245
# File 'lib/enom/domain.rb', line 242

def registration_status
  get_extended_domain_attributes unless @registration_status
  return @registration_status
end

#renew!(options = {}) ⇒ Object



255
256
257
# File 'lib/enom/domain.rb', line 255

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

#unlockObject

Unlock the domain at the registrar to permit transfers



190
191
192
193
194
# File 'lib/enom/domain.rb', line 190

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



207
208
209
# File 'lib/enom/domain.rb', line 207

def unlocked
  !locked?
end

#update_nameservers(nameservers = []) ⇒ Object



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/enom/domain.rb', line 218

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