Class: NominetEPP::Notification
- Inherits:
-
Object
- Object
- NominetEPP::Notification
show all
- Defined in:
- lib/nominet-epp/notification.rb
Defined Under Namespace
Classes: OpenStruct
Constant Summary
collapse
- NAMESPACE_URIS =
{
'urn:ietf:params:xml:ns:domain-1.0' => 'domain',
'urn:ietf:params:xml:ns:contact-1.0' => 'contact',
'http://www.nominet.org.uk/epp/xml/nom-abuse-feed-1.0' => 'abuse',
'http://www.nominet.org.uk/epp/xml/std-notifications-1.0' => 'n',
'http://www.nominet.org.uk/epp/xml/std-notifications-1.1' => 'n',
'http://www.nominet.org.uk/epp/xml/std-notifications-1.2' => 'n',
'http://www.nominet.org.uk/epp/xml/nom-notifications-2.1' => 'n',
'http://www.nominet.org.uk/epp/xml/contact-nom-ext-1.0' => 'contact_ext',
'http://www.nominet.org.uk/epp/xml/std-warning-1.1' => 'warning' }
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Notification.
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/nominet-epp/notification.rb', line 22
def initialize(response)
raise ArgumentError, "must be an EPP::Response" unless response.kind_of?(EPP::Response)
@response = response
@parsed = {}
if response.code == 1301
parse_response
parse_extension
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
74
75
76
77
78
|
# File 'lib/nominet-epp/notification.rb', line 74
def method_missing(method, *args, &block)
return @parsed[method] if @parsed.has_key?(method)
return super unless @response.respond_to?(method)
@response.send(method, *args, &block)
end
|
Instance Method Details
#method(sym) ⇒ Object
90
91
92
|
# File 'lib/nominet-epp/notification.rb', line 90
def method(sym)
respond_to_missing?(sym, true) ? @response.method(sym) : super
end
|
#msgQ_msg ⇒ Object
70
71
72
|
# File 'lib/nominet-epp/notification.rb', line 70
def msgQ_msg
@msgQ_msg ||= @response.msgQ.find('e:msg').first.content.strip
end
|
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
# File 'lib/nominet-epp/notification.rb', line 277
def parse_contact_addr(data)
parsed = {}
data.children.each do |node|
next if node.empty?
case node.name
when 'street'
parsed[:street] = node.content.strip
when 'city'
parsed[:city] = node.content.strip
when 'sp'
parsed[:sp] = node.content.strip
when 'pc'
parsed[:pc] = node.content.strip
when 'cc'
parsed[:cc] = node.content.strip
end
end
parsed
end
|
326
327
328
329
330
331
332
333
334
335
336
337
338
339
|
# File 'lib/nominet-epp/notification.rb', line 326
def parse_contact_ext_infData(ext)
ext.children.each do |node|
next if node.empty?
@parsed[:contact] ||= OpenStruct.new
case node.name
when 'opt-out'
@parsed[:contact].opt_out = node.content.strip == 'Y'
else
@parsed[:contact].send("#{node.name}=", node.content.strip)
end
end
end
|
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
# File 'lib/nominet-epp/notification.rb', line 224
def parse_contact_infData(data)
parsed = {}
data.children.each do |node|
next if node.empty?
case node.name
when 'id'
parsed[:id] = node.content.strip
when 'roid'
parsed[:roid] = node.content.strip
when 'status'
parsed[:status] = node['s'].to_s
when 'postalInfo'
parsed[:postal_info] = parse_contact_postalInfo(node)
when 'voice'
parsed[:voice] = node.content.strip
when 'email'
parsed[:email] = node.content.strip
when 'clID'
parsed[:client_id] = node.content.strip
when 'crID'
parsed[:creator_id] = node.content.strip
when 'crDate'
parsed[:created_date] = Time.parse(node.content.strip)
when 'upID'
parsed[:updator_id] = node.content.strip
when 'upDate'
parsed[:updated_date] = Time.parse(node.content.strip)
end
end
if @parsed.nil? || @parsed.empty?
@parsed = parsed
end
parsed
end
|
#parse_contact_postalInfo(data) ⇒ Object
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
# File 'lib/nominet-epp/notification.rb', line 261
def parse_contact_postalInfo(data)
parsed = {}
data.children.each do |node|
next if node.empty?
case node.name
when 'name'
parsed[:name] = node.content.strip
when 'org'
parsed[:org] = node.content.strip
when 'addr'
parsed[:addr] = parse_contact_addr(node)
end
end
parsed
end
|
#parse_domain_infData(data) ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/nominet-epp/notification.rb', line 139
def parse_domain_infData(data)
parsed = {}
data.children.each do |node|
next if node.empty?
case node.name
when 'name'
parsed[:name] = node.content.strip
when 'roid'
parsed[:roid] = node.content.strip
when 'ns'
parsed[:nameservers] = parse_domain_ns(node)
when 'clID'
parsed[:client_id] = node.content.strip
when 'crID'
parsed[:creator_id] = node.content.strip
when 'crDate'
parsed[:created_date] = Time.parse(node.content.strip)
when 'exDate'
parsed[:expiration_date] = Time.parse(node.content.strip)
end
end
parsed
end
|
#parse_domain_ns(data) ⇒ Object
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/nominet-epp/notification.rb', line 129
def parse_domain_ns(data)
data.children.map do |node|
next if node.empty?
case node.name
when 'hostObj'
node.content.strip
end
end.compact
end
|
#parse_extension ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/nominet-epp/notification.rb', line 105
def parse_extension
[@response.extension].flatten.compact.each do |extension|
ns = NAMESPACE_URIS[extension.namespaces.namespace.href]
name = extension.name.gsub('-', '_')
method = :"parse_#{ns}_#{name}"
if self.respond_to?(method, true)
return self.send(method, extension)
end
end
end
|
#parse_n_cancData(data) ⇒ Object
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/nominet-epp/notification.rb', line 117
def parse_n_cancData(data)
data.children.each do |node|
next if node.empty?
case node.name
when 'domainName'
@parsed[:name] = node.content.strip
when 'orig'
@parsed[:originator] = node.content.strip
end
end
end
|
297
298
299
300
301
302
303
304
305
306
307
308
|
# File 'lib/nominet-epp/notification.rb', line 297
def parse_n_contactDelData(data)
data.children.each do |node|
next if node.empty?
case node.name
when 'contactId'
@parsed[:id] = node.content.strip
when 'roid'
@parsed[:roid] = node.content.strip
end
end
end
|
#parse_n_domainListData(data) ⇒ Object
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/nominet-epp/notification.rb', line 163
def parse_n_domainListData(data)
data.children.map do |node|
next if node.empty?
case node.name
when 'domainName'
node.content.strip
when 'infData'
OpenStruct.new(parse_domain_infData(node))
end
end.compact
end
|
#parse_n_rcData(data) ⇒ Object
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
# File 'lib/nominet-epp/notification.rb', line 309
def parse_n_rcData(data)
data.children.each do |node|
next if node.empty?
case node.name
when 'orig'
@parsed[:originator] = node.content.strip
when 'registrarTag'
@parsed[:registrar_tag] = node.content.strip
when 'domainListData'
@parsed[:domains] = parse_n_domainListData(node)
when 'infData'
@parsed[:contact] = OpenStruct.new(parse_contact_infData(node))
end
end
end
|
#parse_n_relData(data) ⇒ Object
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
# File 'lib/nominet-epp/notification.rb', line 175
def parse_n_relData(data)
data.children.each do |node|
next if node.empty?
case node.name
when 'accountId'
@parsed[:account_id] = node.content.strip
@parsed[:account_moved?] = node['moved'] == 'Y'
when 'from'
@parsed[:from] = node.content.strip
when 'registrarTag'
@parsed[:registrar_tag] = node.content.strip
when 'domainListData'
@parsed[:domains] = parse_n_domainListData(node)
end
end
end
|
#parse_n_suspData(data) ⇒ Object
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
# File 'lib/nominet-epp/notification.rb', line 192
def parse_n_suspData(data)
data.children.each do |node|
next if node.empty?
case node.name
when 'reason'
@parsed[:reason] = node.content.strip
when 'cancelDate'
@parsed[:cancellation_date] = Time.parse(node.content.strip)
when 'domainListData'
@parsed[:domains] = parse_n_domainListData(node)
end
end
end
|
#parse_n_trnData(data) ⇒ Object
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
# File 'lib/nominet-epp/notification.rb', line 206
def parse_n_trnData(data)
data.children.each do |node|
next if node.empty?
case node.name
when 'orig'
@parsed[:originator] = node.content.strip
when 'accountId'
@parsed[:account_id] = node.content.strip
when 'oldAccountId'
@parsed[:old_account_id] = node.content.strip
when 'domainListData'
@parsed[:domains] = parse_n_domainListData(node)
when 'infData'
@parsed[:contact] = OpenStruct.new(parse_contact_infData(node))
end
end
end
|
#parse_response ⇒ Object
96
97
98
99
100
101
102
103
104
|
# File 'lib/nominet-epp/notification.rb', line 96
def parse_response
ns = NAMESPACE_URIS[@response.data.namespaces.namespace.href]
name = @response.data.name.gsub('-', '_')
method = :"parse_#{ns}_#{name}"
if self.respond_to?(method, true)
return self.send(method, @response.data)
end
end
|
#parse_warning_truncated_field(ext) ⇒ Object
341
342
343
344
345
346
347
348
349
|
# File 'lib/nominet-epp/notification.rb', line 341
def parse_warning_truncated_field(ext)
field_name = ext['field-name']
value = ext.content.strip
case field_name
when /:crID$/, /:upID$/
return
end
end
|
#respond_to?(method, include_private = false) ⇒ Boolean
87
88
89
|
# File 'lib/nominet-epp/notification.rb', line 87
def respond_to?(method, include_private = false)
respond_to_missing?(method, include_private) || super
end
|
#respond_to_missing?(method, include_private) ⇒ Boolean
80
81
82
|
# File 'lib/nominet-epp/notification.rb', line 80
def respond_to_missing?(method, include_private)
@parsed.has_key?(method) || @response.respond_to?(method, include_private)
end
|
#type ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/nominet-epp/notification.rb', line 35
def type
@type ||= begin
case msgQ_msg
when /Account Details Change/i
:account_change
when /Contact deleted/i
:contact_deleted
when /DQ Workflow process/i
:data_quality
when /Domain Activity/i
:abuse_feed
when /Domain name Cancellation/i
:domain_cancelled
when /Domains Released/i
:domains_released
when /Domains Suspended/i
:domains_suspended
when /Host cancellation/i
:host_cancellation
when /Referral Accepted/i
:referral_accepted
when /Referral Rejected/i
:referral_rejected
when /Registrant Transfer/i
:registrant_transfer
when /Registrar Change Authorisation Request/i
:handshake_request
when /Registrar Change Handshake Rejected/i
:handshake_rejected
when /Registrar Change Notification/
:registrar_change
end
end
end
|