mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 01:11:43 +02:00
Introduce custom assertion
This commit is contained in:
parent
5939da366e
commit
348e6e5d7a
54 changed files with 378 additions and 389 deletions
|
@ -1,22 +1,27 @@
|
|||
module EPP
|
||||
module Epp
|
||||
class Response
|
||||
attr_accessor :results
|
||||
attr_reader :results
|
||||
|
||||
def self.from_xml(xml)
|
||||
def self.xml(xml)
|
||||
xml_doc = Nokogiri::XML(xml)
|
||||
response = new
|
||||
|
||||
result_elements = xml_doc.css('result')
|
||||
results = []
|
||||
|
||||
result_elements.each do |result_element|
|
||||
response.results << Result.new(result_element[:code].to_s, result_element.text.strip)
|
||||
code_value = result_element[:code]
|
||||
code = Result::Code.new(code_value)
|
||||
results << Result.new(code: code)
|
||||
end
|
||||
|
||||
response
|
||||
new(results: results)
|
||||
end
|
||||
|
||||
def initialize
|
||||
@results = []
|
||||
def initialize(results:)
|
||||
@results = results
|
||||
end
|
||||
|
||||
def code?(code)
|
||||
results.any? { |result| result.code == code }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,27 +1,10 @@
|
|||
module EPP
|
||||
module Epp
|
||||
class Response
|
||||
class Result
|
||||
CODE_TO_TYPE = {
|
||||
'1000' => :success,
|
||||
'1001' => :success_pending,
|
||||
'1300' => :success_empty_queue,
|
||||
'1301' => :success_dequeue,
|
||||
'2001' => :syntax_error,
|
||||
'2003' => :required_param_missing,
|
||||
'2005' => :param_syntax_error,
|
||||
'2308' => :data_management_policy_violation
|
||||
}
|
||||
attr_reader :code
|
||||
|
||||
attr_accessor :code
|
||||
attr_accessor :message
|
||||
|
||||
def initialize(code, message)
|
||||
def initialize(code:)
|
||||
@code = code
|
||||
@message = message
|
||||
end
|
||||
|
||||
def self.codes
|
||||
CODE_TO_TYPE
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
81
app/models/epp/response/result/code.rb
Normal file
81
app/models/epp/response/result/code.rb
Normal file
|
@ -0,0 +1,81 @@
|
|||
module Epp
|
||||
class Response
|
||||
class Result
|
||||
class Code
|
||||
attr_reader :value
|
||||
|
||||
KEY_TO_VALUE = {
|
||||
completed_successfully: 1000,
|
||||
completed_successfully_action_pending: 1001,
|
||||
completed_successfully_no_messages: 1300,
|
||||
completed_successfully_ack_to_dequeue: 1301,
|
||||
completed_successfully_ending_session: 1500,
|
||||
unknown_command: 2000,
|
||||
syntax_error: 2001,
|
||||
use_error: 2002,
|
||||
required_parameter_missing: 2003,
|
||||
parameter_value_range_error: 2004,
|
||||
parameter_value_syntax_error: 2005,
|
||||
billing_failure: 2104,
|
||||
object_is_not_eligible_for_renewal: 2105,
|
||||
authorization_error: 2201,
|
||||
invalid_authorization_information: 2202,
|
||||
object_does_not_exist: 2303,
|
||||
object_status_prohibits_operation: 2304,
|
||||
object_association_prohibits_operation: 2305,
|
||||
parameter_value_policy_error: 2306,
|
||||
data_management_policy_violation: 2308,
|
||||
authentication_error_server_closing_connection: 2501,
|
||||
}.freeze
|
||||
private_constant :KEY_TO_VALUE
|
||||
|
||||
DEFAULT_DESCRIPTIONS = {
|
||||
1000 => 'Command completed successfully',
|
||||
1001 => 'Command completed successfully; action pending',
|
||||
1300 => 'Command completed successfully; no messages',
|
||||
1301 => 'Command completed successfully; ack to dequeue',
|
||||
1500 => 'Command completed successfully; ending session',
|
||||
2000 => 'Unknown command',
|
||||
2001 => 'Command syntax error',
|
||||
2002 => 'Command use error',
|
||||
2003 => 'Required parameter missing',
|
||||
2004 => 'Parameter value range error',
|
||||
2005 => 'Parameter value syntax error',
|
||||
2104 => 'Billing failure',
|
||||
2105 => 'Object is not eligible for renewal',
|
||||
2201 => 'Authorization error',
|
||||
2202 => 'Invalid authorization information',
|
||||
2303 => 'Object does not exist',
|
||||
2304 => 'Object status prohibits operation',
|
||||
2305 => 'Object association prohibits operation',
|
||||
2306 => 'Parameter value policy error',
|
||||
2308 => 'Data management policy violation',
|
||||
2501 => 'Authentication error; server closing connection',
|
||||
}.freeze
|
||||
private_constant :DEFAULT_DESCRIPTIONS
|
||||
|
||||
def self.codes
|
||||
KEY_TO_VALUE
|
||||
end
|
||||
|
||||
def self.default_descriptions
|
||||
DEFAULT_DESCRIPTIONS
|
||||
end
|
||||
|
||||
def self.key(key)
|
||||
new(KEY_TO_VALUE[key])
|
||||
end
|
||||
|
||||
def initialize(value)
|
||||
value = value.to_i
|
||||
raise ArgumentError, "Invalid value: #{value}" unless KEY_TO_VALUE.value?(value)
|
||||
@value = value
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
value == other.value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue