Module: EPPClient::HostmasterDomain

Included in:
Hostmaster
Defined in:
lib/epp-client/hostmaster-domain.rb

Instance Method Summary collapse

Instance Method Details

#domain_check_xml(*domains) ⇒ Object

:nodoc:



3
4
5
6
7
8
9
10
11
# File 'lib/epp-client/hostmaster-domain.rb', line 3

def domain_check_xml(*domains) # :nodoc:
  command do |xml|
    xml.check do
      xml.domain :check, 'xmlns:domain' => EPPClient::SCHEMAS_URL['domain-1.1'] do
        domains.each {|domain| xml.domain :name, domain}
      end
    end
  end
end

#domain_contacts_xml(xml, args) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/epp-client/hostmaster-domain.rb', line 54

def domain_contacts_xml(xml, args)
  args.each do |type,contacts|
    contacts.each do |c|
      xml.domain :contact, { type: type }, c
    end
  end
end

#domain_create_process(xml) ⇒ Object

:nodoc:



81
82
83
84
85
86
87
88
# File 'lib/epp-client/hostmaster-domain.rb', line 81

def domain_create_process(xml) #:nodoc:
  dom = xml.xpath('epp:resData/domain:creData', EPPClient::SCHEMAS_URL)
  ret = {
    name: dom.xpath('domain:name', EPPClient::SCHEMAS_URL).text,
    crDate: DateTime.parse(dom.xpath('domain:crDate', EPPClient::SCHEMAS_URL).text),
    exDate: DateTime.parse(dom.xpath('domain:exDate', EPPClient::SCHEMAS_URL).text),
  }
end

#domain_create_xml(args) ⇒ Object

:nodoc:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/epp-client/hostmaster-domain.rb', line 66

def domain_create_xml(args) #:nodoc:
  command do |xml|
    xml.create do
      xml.domain :create, 'xmlns:domain' => EPPClient::SCHEMAS_URL['domain-1.1'] do
        xml.domain :name, args[:name]
        domain_period_xml(xml, args[:period]) if args.key?(:period)
        domain_nss_xml(xml, args[:ns]) if args.key? :ns
        xml.domain :registrant, args[:registrant]
        domain_contacts_xml(xml, args[:contacts]) if args.key? :contacts
        xml.domain :license, args[:license] if args.key? :license
      end
    end
  end
end

#domain_delete_xml(domain) ⇒ Object

:nodoc:



91
92
93
94
95
96
97
98
99
# File 'lib/epp-client/hostmaster-domain.rb', line 91

def domain_delete_xml(domain) #:nodoc:
  command do |xml|
    xml.delete do
      xml.domain :delete, 'xmlns:domain' => EPPClient::SCHEMAS_URL['domain-1.1'] do
        xml.domain :name, domain
      end
    end
  end
end

#domain_info_xml(args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/epp-client/hostmaster-domain.rb', line 13

def domain_info_xml(args)
  command do |xml|
    xml.info do
      xml.domain :info, 'xmlns:domain' => EPPClient::SCHEMAS_URL['domain-1.1'] do
        xml.domain :name, args[:name]
        if args.key? :authInfo
          xml.domain :authInfo do
            xml.domain :pw, args[:authInfo]
          end
        end
      end
    end
  end
end

#domain_nss_xml(xml, nss) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/epp-client/hostmaster-domain.rb', line 28

def domain_nss_xml(xml, nss)
  xml.domain :ns do
    if nss.first.is_a? Hash
      nss.each do |ns|
        xml.domain :hostAttr do
          xml.domain :hostName, ns[:hostName]
          if ns.key?(:hostAddrv4)
            ns[:hostAddrv4].each do |v4|
              xml.domain :hostAddr, {:ip => :v4}, v4
            end
          end
          if ns.key?(:hostAddrv6)
            ns[:hostAddrv6].each do |v6|
              xml.domain :hostAddr, {:ip => :v6}, v6
            end
          end
        end
      end
    else
      nss.each do |ns|
        xml.domain :hostObj, ns
      end
    end
  end
end

#domain_period_xml(xml, period) ⇒ Object



62
63
64
# File 'lib/epp-client/hostmaster-domain.rb', line 62

def domain_period_xml(xml, period)
  xml.domain :period, { unit: period[:unit] }, period[:number]
end

#domain_renew(domain) ⇒ Object

Renew a domain

Takes a hash as an argument, containing the following keys :

:name

the domain name

:period

an optionnal hash containing the period for withch the domain is registered with the following keys :

:unit

the unit of time, either “m”onth or “y”ear.

:number

the number of unit of time.

:curExpDate

the date identifying the current end of the domain object registration period.

Returns a hash with the following keys :

:name

the fully qualified name of the domain object.

:exDate

the date and time identifying the end of the domain object’s registration period.



132
133
134
135
136
# File 'lib/epp-client/hostmaster-domain.rb', line 132

def domain_renew(domain)
  domain[:curExpDate] = DateTime.parse(domain[:curExpDate]) unless domain[:curExpDate].is_a? DateTime
  response = send_request(domain_renew_xml(domain))
  get_result(:xml => response, :callback => :domain_renew_process)
end

#domain_renew_process(xml) ⇒ Object

:nodoc:



138
139
140
141
142
143
144
# File 'lib/epp-client/hostmaster-domain.rb', line 138

def domain_renew_process(xml) #:nodoc:
  dom = xml.xpath('epp:resData/domain:renData', EPPClient::SCHEMAS_URL)
  ret = {
    name: dom.xpath('domain:name', EPPClient::SCHEMAS_URL).text,
    exDate: DateTime.parse(dom.xpath('domain:exDate', EPPClient::SCHEMAS_URL).text)
  }
end

#domain_renew_xml(domain) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/epp-client/hostmaster-domain.rb', line 101

def domain_renew_xml(domain)
  command do |xml|
    xml.renew do
      xml.domain :renew, 'xmlns:domain' => EPPClient::SCHEMAS_URL['domain-1.1'] do
        xml.domain :name, domain[:name]
        xml.domain :curExpDate, domain[:curExpDate].strftime('%Y-%m-%d')
        domain_period_xml(xml, domain[:period])
      end
    end
  end
end

#domain_update_xml(args) ⇒ Object

:nodoc:



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/epp-client/hostmaster-domain.rb', line 146

def domain_update_xml(args) #:nodoc:
  command do |xml|
    xml.update do
      xml.domain :update, 'xmlns:domain' => EPPClient::SCHEMAS_URL['domain-1.1'] do
        xml.domain :name, args[:name]
        [:add, :rem].each do |ar|
          next unless args.key?(ar) && (args[ar].key?(:ns) || args[ar].key?(:contacts) || args[ar].key?(:status))
          xml.domain ar do
            domain_nss_xml(xml, args[ar][:ns]) if args[ar].key? :ns
            domain_contacts_xml(xml, args[ar][:contacts]) if args[ar].key? :contacts
            if args[ar].key? :status
              args[ar][:status].each do |st,text|
                if text.nil?
                  xml.domain :status, s: st
                else
                  xml.domain :status, { s: st }, text
                end
              end
            end
          end
        end
        if args.key?(:chg) && (args[:chg].key?(:registrant) || args[:chg].key?(:authInfo))
          xml.domain :chg do
            xml.domain :registrant, args[:chg][:registrant] if args[:chg].key? :registrant
            if args[:chg].key? :authInfo
              xml.domain :authInfo do
                xml.domain :pw, args[:chg][:authInfo]
              end
            end
          end
        end
      end
    end
  end
end