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



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

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)


45
46
47
48
49
# File 'lib/enom/domain.rb', line 45

def self.available?(name)
  sld, tld = name.split(".")
  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



40
41
42
# File 'lib/enom/domain.rb', line 40

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



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

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.blank?
    end
  end

  return result
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



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

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



138
139
140
141
142
143
144
# File 'lib/enom/domain.rb', line 138

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

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

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



148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/enom/domain.rb', line 148

def self.suggest(name, options ={})
  sld, tld = name.split(".")
  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|
    %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



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/enom/domain.rb', line 116

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

  # 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)


228
229
230
# File 'lib/enom/domain.rb', line 228

def active?
  registration_status == "Registered"
end

#expired?Boolean

Returns:

  • (Boolean)


232
233
234
# File 'lib/enom/domain.rb', line 232

def expired?
  registration_status == "Expired"
end

#lockObject

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



164
165
166
167
168
# File 'lib/enom/domain.rb', line 164

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



178
179
180
181
182
183
184
# File 'lib/enom/domain.rb', line 178

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



194
195
196
197
# File 'lib/enom/domain.rb', line 194

def nameservers
  get_extended_domain_attributes unless @nameservers
  return @nameservers
end

#registration_statusObject



223
224
225
226
# File 'lib/enom/domain.rb', line 223

def registration_status
  get_extended_domain_attributes unless @registration_status
  return @registration_status
end

#renew!(options = {}) ⇒ Object



236
237
238
# File 'lib/enom/domain.rb', line 236

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

#unlockObject

Unlock the domain at the registrar to permit transfers



171
172
173
174
175
# File 'lib/enom/domain.rb', line 171

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



188
189
190
# File 'lib/enom/domain.rb', line 188

def unlocked
  !locked?
end

#update_nameservers(nameservers = []) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/enom/domain.rb', line 199

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