Class: EnomAPI::Registrant

Inherits:
Object
  • Object
show all
Defined in:
lib/enom-api/registrant.rb

Overview

Represents a registrant or other type of Contact in the eNom API

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(first, last) {|registrant| ... } ⇒ Registrant

Returns a new instance of Registrant.

Parameters:

  • first (String)

    Registrant first name

  • last (String)

    Registrant last name

Yields:

  • registrant

Yield Parameters:

  • registrant (Registrant)

    receiver to configure

Raises:

  • (ArgumentError)


47
48
49
50
51
52
# File 'lib/enom-api/registrant.rb', line 47

def initialize(first, last, &blk)
  raise ArgumentError, "first and last may not be nil" unless first && last

  @firstname, @lastname = first, last
  yield self if blk
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



40
41
42
# File 'lib/enom-api/registrant.rb', line 40

def address
  @address
end

#cityObject

Returns the value of attribute city.



40
41
42
# File 'lib/enom-api/registrant.rb', line 40

def city
  @city
end

#countryObject

Returns the value of attribute country.



40
41
42
# File 'lib/enom-api/registrant.rb', line 40

def country
  @country
end

#emailObject

Returns the value of attribute email.



40
41
42
# File 'lib/enom-api/registrant.rb', line 40

def email
  @email
end

#faxObject

Returns the value of attribute fax.



40
41
42
# File 'lib/enom-api/registrant.rb', line 40

def fax
  @fax
end

#firstnameObject

Returns the value of attribute firstname.



40
41
42
# File 'lib/enom-api/registrant.rb', line 40

def firstname
  @firstname
end

#idObject

Returns the value of attribute id.



40
41
42
# File 'lib/enom-api/registrant.rb', line 40

def id
  @id
end

#job_titleObject

Returns the value of attribute job_title.



40
41
42
# File 'lib/enom-api/registrant.rb', line 40

def job_title
  @job_title
end

#lastnameObject

Returns the value of attribute lastname.



40
41
42
# File 'lib/enom-api/registrant.rb', line 40

def lastname
  @lastname
end

#organisationObject

Returns the value of attribute organisation.



40
41
42
# File 'lib/enom-api/registrant.rb', line 40

def organisation
  @organisation
end

#phoneObject

Returns the value of attribute phone.



40
41
42
# File 'lib/enom-api/registrant.rb', line 40

def phone
  @phone
end

#phone_extensionObject

Returns the value of attribute phone_extension.



40
41
42
# File 'lib/enom-api/registrant.rb', line 40

def phone_extension
  @phone_extension
end

#postal_codeObject

Returns the value of attribute postal_code.



40
41
42
# File 'lib/enom-api/registrant.rb', line 40

def postal_code
  @postal_code
end

#stateObject

Returns the value of attribute state.



40
41
42
# File 'lib/enom-api/registrant.rb', line 40

def state
  @state
end

Class Method Details

.from_xml(xmldoc) ⇒ Registrant

Returns Registrant composed from the information in the xmldoc.

Parameters:

  • xmldoc (Demolisher, String)

    Demolisher or XML String of registrant information

Returns:

  • (Registrant)

    Registrant composed from the information in the xmldoc



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/enom-api/registrant.rb', line 8

def self.from_xml(xmldoc)
  return if xmldoc.nil?

  @xml = xml = xmldoc.kind_of?(Demolisher::Node) ? xmldoc : Demolisher.demolish(xmldoc.to_s)
  r = new("", "")

  mapping = if xml.FName
    from_xml_mapping_one
  elsif xml.RegistrantFirstName
    from_xml_mapping_two('Registrant')
  elsif xml.AuxBillingFirstName
    from_xml_mapping_two('AuxBilling')
  elsif xml.TechFirstName
    from_xml_mapping_two('Tech')
  elsif xml.AdminFirstName
    from_xml_mapping_two('Admin')
  elsif xml.BillingFirstName
    from_xml_mapping_two('Billing')
  end

  mapping.each do |meth, el|
    case el
    when Array
      r.send(:"#{meth}=", el.map { |n| xml.send(n).to_s }.delete_if { |n| n.nil? || n == "" }.join("\n"))
    else
      r.send(:"#{meth}=", xml.send(el).to_s)
    end
  end

  r
end

Instance Method Details

#to_post_data(prefix = nil) ⇒ Hash

Converts the object into a form suitable for POSTing to the eNom API

Parameters:

  • prefix (String) (defaults to: nil)

    String to prepend to key names

Returns:

  • (Hash)

    Hash of data for the registrant



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/enom-api/registrant.rb', line 58

def to_post_data(prefix=nil)
  data = {
    "#{prefix}FirstName" => firstname,
    "#{prefix}LastName" => lastname,
    "#{prefix}City" => city,
    "#{prefix}StateProvince" => state,
    "#{prefix}PostalCode" => postal_code,
    "#{prefix}Country" => country,
    "#{prefix}EmailAddress" => email,
    "#{prefix}Phone" => phone,
    "#{prefix}Fax" => fax }
  data["#{prefix}Address1"], data["#{prefix}Address2"] = address && address.split("\n", 2)

  unless organisation.nil? || organisation == ''
    data["#{prefix}OrganizationName"] = organisation
    data["#{prefix}JobTitle"] = (job_title || "Domains Manager")
  end

  data.reject { |_,v| v.nil? || v == '' }
end