Class: Enom::Domain
- Inherits:
-
Object
- Object
- Enom::Domain
- Includes:
- ContactInfo, HTTParty
- Defined in:
- lib/enom/domain.rb
Constant Summary
Constants included from ContactInfo
ContactInfo::CONTACT_TYPES, ContactInfo::FIELDS
Instance Attribute Summary collapse
-
#expiration_date ⇒ Object
readonly
Domain expiration date (currently returns a string - 11/9/2010 11:57:39 AM).
-
#name ⇒ Object
readonly
The domain name on Enom.
-
#sld ⇒ Object
readonly
Second-level and first-level domain on Enom.
-
#tld ⇒ Object
readonly
Second-level and first-level domain on Enom.
Class Method Summary collapse
-
.all(options = {}) ⇒ Object
Find and return all domains in the account.
-
.available?(name) ⇒ Boolean
Boolean helper method to determine if the domain is available for purchase.
-
.check(name) ⇒ Object
Determine if the domain is available for purchase.
-
.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.
-
.delete!(name, options = {}) ⇒ Object
Delete a domain name registration from your account.
-
.find(name) ⇒ Object
Find the domain (must be in your account) on Enom.
-
.parse_sld_and_tld(domain_name) ⇒ Object
Parse out domain name tld and sld from the PublicSuffix lib.
-
.register!(name, options = {}) ⇒ Object
Purchase the domain.
-
.renew!(name, options = {}) ⇒ Object
Renew the domain.
-
.suggest(name, options = {}) ⇒ Object
Suggest available domains using the namespinner Returns an array of available domain names that match.
-
.transfer!(name, auth, options = {}) ⇒ Object
Transfer domain from another registrar to Enom, charges the account when successful Returns true if successful, false if failed.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #expired? ⇒ Boolean
-
#initialize(attributes) ⇒ Domain
constructor
A new instance of Domain.
-
#lock ⇒ Object
Lock the domain at the registrar so it can“t be transferred.
-
#locked ⇒ Object
(also: #locked?)
Check if the domain is currently locked.
-
#nameservers ⇒ Object
Return the DNS nameservers that are currently used for the domain.
- #registration_status ⇒ Object
- #renew!(options = {}) ⇒ Object
-
#unlock ⇒ Object
Unlock the domain at the registrar to permit transfers.
-
#unlocked ⇒ Object
(also: #unlocked?)
Check if the domain is currently unlocked.
- #update_nameservers(nameservers = []) ⇒ Object
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_date ⇒ Object (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 |
#name ⇒ Object (readonly)
The domain name on Enom
10 11 12 |
# File 'lib/enom/domain.rb', line 10 def name @name end |
#sld ⇒ Object (readonly)
Second-level and first-level domain on Enom
13 14 15 |
# File 'lib/enom/domain.rb', line 13 def sld @sld end |
#tld ⇒ Object (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( = {}) 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
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, = {}) sld, tld = parse_sld_and_tld(name) response = Client.request({'Command' => 'DeleteRegistration', 'SLD' => sld, 'TLD' => tld}.merge())['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, = {}) sld, tld = parse_sld_and_tld(name) opts = {} if [:nameservers] count = 1 [:nameservers].each do |nameserver| opts.merge!("NS#{count}" => nameserver) count += 1 end else opts.merge!("UseDNS" => "default") end opts.merge!("NumYears" => [:years]) if [: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, = {}) sld, tld = parse_sld_and_tld(name) opts = {} opts.merge!("NumYears" => [:years]) if [: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, ={}) sld, tld = parse_sld_and_tld(name) opts = {} opts.merge!("MaxResults" => [:max_results] || 8, "Similar" => [:similar] || "High") response = Client.request({"Command" => "namespinner", "SLD" => sld, "TLD" => tld}.merge(opts)) suggestions = [] response["interface_response"]["namespin"]["domains"]["domain"].map do |d| ([: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, = {}) 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 [:renew] response = Client.request({"Command" => "TP_CreateOrder"}.merge(opts))["ErrCount"] response.to_i == 0 end |
Instance Method Details
#active? ⇒ Boolean
247 248 249 |
# File 'lib/enom/domain.rb', line 247 def active? registration_status == "Registered" end |
#expired? ⇒ Boolean
251 252 253 |
# File 'lib/enom/domain.rb', line 251 def expired? registration_status == "Expired" end |
#lock ⇒ Object
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 |
#locked ⇒ Object 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 |
#nameservers ⇒ Object
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_status ⇒ Object
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!( = {}) Domain.renew!(name, ) end |
#unlock ⇒ Object
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 |
#unlocked ⇒ Object 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 |