Class: Registrar::Provider::Enom

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/registrar/provider/enom.rb,
lib/registrar/provider/enom/order.rb,
lib/registrar/provider/enom/contact.rb,
lib/registrar/provider/enom/extended_attribute.rb,
lib/registrar/provider/enom/extended_attribute_ca.rb,
lib/registrar/provider/enom/extended_attribute_io.rb,
lib/registrar/provider/enom/extended_attribute_us.rb

Overview

:nodoc:

Defined Under Namespace

Modules: ExtendedAttributeCA, ExtendedAttributeIO, ExtendedAttributeUS Classes: Contact, ExtendedAttribute, Order

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, username, password) ⇒ Enom

Returns a new instance of Enom.



16
17
18
19
20
# File 'lib/registrar/provider/enom.rb', line 16

def initialize(url, username, password)
  @url = url
  @username = username
  @password = password
end

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



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

def password
  @password
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

#usernameObject

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

#auto_renew?(name) ⇒ Boolean

Returns:

  • (Boolean)


113
114
115
116
117
118
# File 'lib/registrar/provider/enom.rb', line 113

def auto_renew?(name)
  sld, tld = parse(name)
  query = base_query.merge('Command' => 'GetRenew', 'TLD' => tld, 'SLD' => sld)
  response = execute_command(query)
  response['auto_renew'] == '1'
end

#available?(name) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
# File 'lib/registrar/provider/enom.rb', line 29

def available?(name)
  sld, tld = parse(name)
  
  query = base_query.merge('Command' => 'Check')
  response = execute(query.merge('SLD' => sld, 'TLD' => tld))
  
  response['RRPCode'] == '210'
end

#contacts(domain) ⇒ Object

Get a Hash of all of the contacts for the domain. The Hash will have the following key/value pairs:

* :registrant => The domain registrant
* :aux_billing => An customer specified billing contact
* :tech => The technical contact for the domain
* :admin => The administrative contact for the domain
* :billing => The Enom billing contact (DNSimple)


259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/registrar/provider/enom.rb', line 259

def contacts(domain)
  sld, tld = parse(domain.name)
  
  query = base_query.merge('Command' => 'GetContacts', 'TLD' => tld, 'SLD' => sld)

  response = execute(query)

  contacts = {}
  registrant_hash = response['GetContacts']['Registrant']
  contacts[:registrant] = Enom::Contact.from_response('Registrant', registrant_hash)
  aux_billing_hash = response['GetContacts']['AuxBilling']
  contacts[:aux_billing] = Enom::Contact.from_response('AuxBilling', aux_billing_hash) 

  tech_hash = response['GetContacts']['Tech']
  contacts[:tech] = Enom::Contact.from_response('Tech', tech_hash)

  admin_hash = response['GetContacts']['Admin']
  contacts[:admin] = Enom::Contact.from_response('Admin', admin_hash)

  billing_hash = response['GetContacts']['Billing']
  contacts[:billing] = Enom::Contact.from_response('Billing', billing_hash)

  contacts
end

#disable_auto_renewal(name) ⇒ Object



128
129
130
131
132
133
134
# File 'lib/registrar/provider/enom.rb', line 128

def disable_auto_renewal(name)
  sld, tld = parse(name)
  query = base_query.merge('Command' => 'SetRenew', 'TLD' => tld, 'SLD' => sld)
  query = query.merge('RenewFlag' => '0')
  response = execute_command(query)
  response['RenewName'] == 'False'
end

#enable_auto_renewal(name) ⇒ Object



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

def enable_auto_renewal(name)
  sld, tld = parse(name)
  query = base_query.merge('Command' => 'SetRenew', 'TLD' => tld, 'SLD' => sld)
  query = query.merge('RenewFlag' => '1')
  response = execute_command(query)
  response['RenewName'] == 'True'
end

#extended_attributes(name) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/registrar/provider/enom.rb', line 207

def extended_attributes(name)
  sld, tld = parse(name)
  query = base_query.merge('Command' => 'GetExtAttributes', 'TLD' => tld)
  response = execute(query)
  return nil unless response['Attributes']
  [response['Attributes']['Attribute']].flatten.map do |enom_attribute|
    extended_attribute = Registrar::ExtendedAttributeDescriptor.new
    extended_attribute.name = enom_attribute['Name']
    extended_attribute.description = enom_attribute['Description']
    extended_attribute.child = enom_attribute['IsChild'] == '1'
    extended_attribute.required = enom_attribute['Required'] == '1'
    extended_attribute.application = enom_attribute['Application']
    extended_attribute.user_defined = enom_attribute['UserDefined'] == 'True'
    extended_attribute.apply_to_registrar = enom_attribute['Application'] == '2'

    if enom_attribute['Options']
      extended_attribute.options = [enom_attribute['Options']['Option']].flatten.map do |enom_option|
        option = Registrar::ExtendedAttributeOptionDescriptor.new
        option.title = enom_option['Title']
        option.value = enom_option['Value']
        option.description = enom_option['Description']
        option
      end
    end

    extended_attribute
  end
end

#find(name) ⇒ Object



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

def find(name)
  sld, tld = parse(name)
  query = base_query.merge('Command' => 'GetDomainInfo')

  response = execute(query.merge('SLD' => sld, 'TLD' => tld))
  
  domain = Registrar::Domain.new(name) 
  domain.expiration = response['GetDomainInfo']['status']['expiration']
  domain.registration_status = response['GetDomainInfo']['status']['registrationstatus']
  domain.order = order_for_domain(name)
  domain
end

#find_name_server(name) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/registrar/provider/enom.rb', line 181

def find_name_server(name)
  query = base_query.merge('Command' => 'CheckNSStatus', 'CheckNSName' => name)
  response = execute_command(query)
  
  if response['NsCheckSuccess'] == '1'
    name_server = Registrar::NameServer.new(response['CheckNsStatus']['name'])
    name_server.ip_address = response['CheckNsStatus']['ipaddress']
    name_server
  else
    raise RuntimeError, "Name server not found for #{name}"
  end 
end

#minimum_number_of_years(tld) ⇒ Object



236
237
238
239
240
241
242
243
244
245
# File 'lib/registrar/provider/enom.rb', line 236

def minimum_number_of_years(tld)
  {
    'co.uk' => 2,
    'org.uk' => 2,
    'nu' => 2,
    'tm' => 10,
    'com.mx' => 2,
    'me.uk' => 2
  }[tld] || 1
end

#name_servers(name) ⇒ Object Also known as: nameservers



154
155
156
157
158
159
# File 'lib/registrar/provider/enom.rb', line 154

def name_servers(name)
  sld, tld = parse(name)
  query = base_query.merge('Command' => 'GetDNS', 'TLD' => tld, 'SLD' => sld)
  response = execute_command(query)
  [response['dns']].flatten
end

#order(id) ⇒ Object



136
137
138
139
140
141
142
143
144
145
# File 'lib/registrar/provider/enom.rb', line 136

def order(id)
  query = base_query.merge('Command' => 'GetOrderDetail', 'OrderID' => id.to_s)
  response = execute(query)

  order = Enom::Order.new(response['Order']['OrderID'])
  order.order_date = response['Order']['OrderDate']
  order.order_status = response['Order']['OrderDetail']['OrderStatus']
  order.status = response['Order']['OrderDetail']['Status']
  order.to_order
end

#order_for_domain(name) ⇒ Object



147
148
149
150
151
152
# File 'lib/registrar/provider/enom.rb', line 147

def order_for_domain(name)
  sld, tld = parse(name)
  query = base_query.merge('Command' => 'GetDomainStatus', 'SLD' => sld, 'TLD' => tld)
  response = execute_command(query)
  order(response['DomainStatus']['OrderID'])
end

#parse(name) ⇒ Object



22
23
24
25
26
27
# File 'lib/registrar/provider/enom.rb', line 22

def parse(name)
  query = base_query.merge('Command' => 'ParseDomain')
  response = execute(query.merge('PassedDomain' => name))
  
  [response['ParseDomain']['SLD'], response['ParseDomain']['TLD']] 
end

#purchase(name, registrant, purchase_options = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/registrar/provider/enom.rb', line 51

def purchase(name, registrant, purchase_options=nil)
  purchase_options ||= Registrar::PurchaseOptions.new

  sld, tld = parse(name)
  query = base_query.merge('Command' => 'Purchase', 'SLD' => sld, 'TLD' => tld)
  registrant = Enom::Contact.new(registrant)
       
  if registrant
    query.merge!(registrant.to_query("Registrant"))
    query.merge!(registrant.to_query("AuxBilling"))
    query.merge!(registrant.to_query("Tech"))
    query.merge!(registrant.to_query("Admin"))
  end

  if purchase_options.has_name_servers? 
    query['IgnoreNSFail'] = 'Yes'
    purchase_options.name_servers.each_with_index do |name_server, i|
      case name_server
      when String
        query["NS#{i+1}"] = name_server
      else
        query["NS#{i+1}"] = name_server.name
      end
      
    end
  else
    query['UseDNS'] = 'default'
  end

  if purchase_options.has_extended_attributes?
    extended_attributes = purchase_options.extended_attributes.map { |a| Enom::ExtendedAttribute.new(a) }
    extended_attributes.each do |extended_attribute| 
      query[extended_attribute.name] = extended_attribute.value
    end
  end

  query['NumYears'] = purchase_options.number_of_years || minimum_number_of_years(tld)
  query['IDNCode'] = purchase_options.language if purchase_options.language

  response = execute(query)

  registrant.identifier = response['RegistrantPartyID']

  domain = Registrar::Domain.new(name) 
  domain.registrant = registrant
  domain.lockable = response['IsLockable'].downcase == 'true'
  domain.real_time = response['IsRealTimeTLD'].downcase == 'true'
  order = order(response['OrderID'])
  order.domains << domain
  domain.order = order
  order
end

#register_name_server(name_server) ⇒ Object



194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/registrar/provider/enom.rb', line 194

def register_name_server(name_server)
  query = base_query.merge('Command' => 'RegisterNameServer', 'Add' => 'true', 'NSName' => name_server.name, 'IP' => name_server.ip_address)
  response = execute_command(query)

  if response['RRPCode'] == '200'
    name_server = Registrar::NameServer.new(response['RegisterNameserver']['NS'])
    name_server.ip_address = response['RegisterNameserver']['IP']
    name_server
  else
    raise RuntimeError, "Unable to create name server: #{response['RRPText']}"
  end
end

#renew(name, renewal_options = nil) ⇒ Object



104
105
106
107
108
109
110
111
# File 'lib/registrar/provider/enom.rb', line 104

def renew(name, renewal_options=nil)
  renewal_options ||= Registrar::RenewalOptions.new
  sld, tld = parse(name)
  query = base_query.merge('Command' => 'Extend', 'SLD' => sld, 'TLD' => tld)
  query = query.merge('NumYears' => renewal_options.number_of_years)
  response = execute(query)
  response['Extension'] && response['Extension'].downcase == 'successful'
end

#set_name_servers(name, name_servers = []) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/registrar/provider/enom.rb', line 162

def set_name_servers(name, name_servers=[])
  sld, tld = parse(name)
  query = base_query.merge('Command' => 'ModifyNS', 'TLD' => tld, 'SLD' => sld)

  name_server_hash = {}
  if name_servers.length == 0
    name_server_hash["NS1"] = ""
  else
    name_servers.each_with_index do |ns_name, index|
      name_server_hash["NS#{index + 1}"] = ns_name
    end
  end
  query = query.merge(name_server_hash)

  response = execute_command(query)

  name_servers
end

#tld_retail_transfer_price(tld) ⇒ Object



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

def tld_retail_transfer_price(tld)
  Enom::PricingEngine.tld_retail_transfer_price(tld)
end

#update_administrative_contact(domain, contact) ⇒ Object

Update the admin contact for the domain.



354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# File 'lib/registrar/provider/enom.rb', line 354

def update_administrative_contact(domain, contact)
  contact = Enom::Contact.new(contact)

  sld, tld = parse(domain.name)
  query = base_query.merge(
    'Command' => 'Contacts',
    'TLD' => tld,
    'SLD' => sld
  )

  query = query.merge('ContactType' => 'Admin')
  query = query.merge(contact.to_query('Admin'))
  response = execute(query)
  contacts(domain)[:admin]
end

#update_aux_billing_contact(domain, contact) ⇒ Object

Update the aux billing contact for the domain.



371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/registrar/provider/enom.rb', line 371

def update_aux_billing_contact(domain, contact)
  contact = Enom::Contact.new(contact)

  sld, tld = parse(domain.name)
  query = base_query.merge(
    'Command' => 'Contacts',
    'TLD' => tld,
    'SLD' => sld
  )

  query = query.merge('ContactType' => 'AuxBilling')
  query = query.merge(contact.to_query('AuxBilling'))
  response = execute(query)
  contacts(domain)[:aux_billing]
end

#update_contacts(domain, contact) ⇒ Object

Update the tech, aux billing and administrative contacts for the domain. Right now the same contact must be used for all of these contact types.



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/registrar/provider/enom.rb', line 311

def update_contacts(domain, contact)
  contact = Enom::Contact.new(contact)

  sld, tld = parse(domain.name)
  query = base_query.merge(
    'Command' => 'Contacts',
    'TLD' => tld,
    'SLD' => sld
  )

  tech_contact_query = query.merge('ContactType' => 'Tech')
  tech_contact_query = tech_contact_query.merge(contact.to_query('Tech'))
  response = execute_command(tech_contact_query)

  admin_contact_query = query.merge('ContactType' => 'Admin')
  admin_contact_query = admin_contact_query.merge(contact.to_query('Admin'))
  response = execute_command(admin_contact_query)

  billing_contact_query = query.merge('ContactType' => 'AuxBilling')
  billing_contact_query = billing_contact_query.merge(contact.to_query('AuxBilling'))
  response = execute(billing_contact_query)

  contacts(domain)
end

#update_registrant(domain, registrant, extended_attributes = nil) ⇒ Object

Update the registrant information for a domain. For some TLDs this will include providing extended attributes. If the TLD does not require extended attributes then send nil or an empty Hash for the extended_attributes argument.



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/registrar/provider/enom.rb', line 287

def update_registrant(domain, registrant, extended_attributes=nil)
  registrant = Enom::Contact.new(registrant)

  sld, tld = parse(domain.name)
  query = base_query.merge(
    'Command' => 'Contacts',
    'TLD' => tld,
    'SLD' => sld
  )

  query = query.merge('ContactType' => 'Registrant')
  query = query.merge(registrant.to_query('Registrant'))

  if extended_attributes
    extended_attributes.each do |name, value| 
      query[name] = value
    end
  end

  response = execute_command(query) # TODO: should something else be returned here?
end

#update_technical_contact(domain, contact) ⇒ Object

Update the tech contact for the domain.



337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'lib/registrar/provider/enom.rb', line 337

def update_technical_contact(domain, contact)
  contact = Enom::Contact.new(contact)

  sld, tld = parse(domain.name)
  query = base_query.merge(
    'Command' => 'Contacts',
    'TLD' => tld,
    'SLD' => sld
  )

  query = query.merge('ContactType' => 'Tech')
  query = query.merge(contact.to_query('Tech'))
  response = execute(query)
  contacts(domain)[:tech]
end