Module: EPPClient::XML
- Included in:
- Base
- Defined in:
- lib/epp-client/xml.rb
Overview
This handles all the XML I/O
Instance Attribute Summary collapse
-
#msgQ_count ⇒ Object
readonly
Returns the value of attribute msgQ_count.
-
#msgQ_id ⇒ Object
readonly
Returns the value of attribute msgQ_id.
-
#recv_xml ⇒ Object
readonly
Returns the value of attribute recv_xml.
-
#sent_xml ⇒ Object
readonly
Returns the value of attribute sent_xml.
-
#trID ⇒ Object
readonly
Returns the value of attribute trID.
Instance Method Summary collapse
-
#builder(opts = {}) ⇒ Object
creates a Builder::XmlMarkup object, mostly only used by
command. -
#command(*args, &_block) ⇒ Object
Creates the xml for the command.
-
#extension ⇒ Object
Wraps the content in an epp:extension.
-
#get_result(args) ⇒ Object
Takes a xml response and checks that the result is in the right range of results, that is, between 1000 and 1999, which are results meaning all went well.
- #get_trid(xml) ⇒ Object
-
#insert_extension(xml1, xml2, pattern = /<clTRID>/) ⇒ Object
Insert xml2 in xml1 before pattern.
-
#raw_builder(opts = {}) {|xml| ... } ⇒ Object
:nodoc:.
-
#recv_frame_to_xml ⇒ Object
:nodoc:.
-
#sent_frame_to_xml ⇒ Object
:nodoc:.
Instance Attribute Details
#msgQ_count ⇒ Object (readonly)
Returns the value of attribute msgQ_count.
4 5 6 |
# File 'lib/epp-client/xml.rb', line 4 def msgQ_count @msgQ_count end |
#msgQ_id ⇒ Object (readonly)
Returns the value of attribute msgQ_id.
4 5 6 |
# File 'lib/epp-client/xml.rb', line 4 def msgQ_id @msgQ_id end |
#recv_xml ⇒ Object (readonly)
Returns the value of attribute recv_xml.
4 5 6 |
# File 'lib/epp-client/xml.rb', line 4 def recv_xml @recv_xml end |
#sent_xml ⇒ Object (readonly)
Returns the value of attribute sent_xml.
4 5 6 |
# File 'lib/epp-client/xml.rb', line 4 def sent_xml @sent_xml end |
#trID ⇒ Object (readonly)
Returns the value of attribute trID.
4 5 6 |
# File 'lib/epp-client/xml.rb', line 4 def trID @trID end |
Instance Method Details
#builder(opts = {}) ⇒ Object
creates a Builder::XmlMarkup object, mostly only used by command
33 34 35 36 37 38 39 40 |
# File 'lib/epp-client/xml.rb', line 33 def builder(opts = {}) raw_builder(opts) do |xml| xml.instruct! :xml, :version => '1.0', :encoding => 'UTF-8' xml.epp('xmlns' => EPPClient::SCHEMAS_URL['epp'], 'xmlns:epp' => EPPClient::SCHEMAS_URL['epp']) do yield xml end end end |
#command(*args, &_block) ⇒ Object
Creates the xml for the command.
You can either pass a block to it, in that case, it’s the command body, or a series of procs, the first one being the commands, the other ones being the extensions.
command do |xml|
xml.logout
end
or
command(lambda do |xml|
xml.logout
end, lambda do |xml|
xml.extension
end)
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/epp-client/xml.rb', line 114 def command(*args, &_block) builder do |xml| xml.command do if block_given? yield xml else command = args.shift command.call(xml) args.each do |ext| xml.extension do ext.call(xml) end end end xml.clTRID(clTRID) end end end |
#extension ⇒ Object
Wraps the content in an epp:extension.
134 135 136 137 138 139 140 |
# File 'lib/epp-client/xml.rb', line 134 def extension raw_builder do |xml| xml.extension do yield(xml) end end end |
#get_result(args) ⇒ Object
Takes a xml response and checks that the result is in the right range of results, that is, between 1000 and 1999, which are results meaning all went well.
In case all went well, it either calls the callback if given, or returns true.
In case there was a problem, an EPPErrorResponse exception is raised.
50 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 |
# File 'lib/epp-client/xml.rb', line 50 def get_result(args) xml = case args when Hash args.delete(:xml) else xml = args args = {} xml end args[:range] ||= 1000..1999 if !(mq = xml.xpath('epp:epp/epp:response/epp:msgQ', EPPClient::SCHEMAS_URL)).empty? @msgQ_count = mq.attribute('count').value.to_i @msgQ_id = mq.attribute('id').value puts "DEBUG: MSGQ : count=#{@msgQ_count}, id=#{@msgQ_id}\n" if debug else @msgQ_count = 0 @msgQ_id = nil end unless (trID = xml.xpath('epp:epp/epp:response/epp:trID', EPPClient::SCHEMAS_URL)).empty? @trID = get_trid(trID) end res = xml.xpath('epp:epp/epp:response/epp:result', EPPClient::SCHEMAS_URL) code = res.attribute('code').value.to_i raise EPPClient::EPPErrorResponse.new(:xml => xml, :code => code, :message => res.xpath('epp:msg', EPPClient::SCHEMAS_URL).text) unless args[:range].include?(code) return true unless args.key?(:callback) case cb = args[:callback] when Symbol return send(cb, xml.xpath('epp:epp/epp:response', EPPClient::SCHEMAS_URL)) else raise ArgumentError, 'Invalid callback type' end end |
#get_trid(xml) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/epp-client/xml.rb', line 90 def get_trid(xml) { :clTRID => xml.xpath('epp:clTRID', EPPClient::SCHEMAS_URL).text, :svTRID => xml.xpath('epp:svTRID', EPPClient::SCHEMAS_URL).text, } end |
#insert_extension(xml1, xml2, pattern = /<clTRID>/) ⇒ Object
Insert xml2 in xml1 before pattern
143 144 145 |
# File 'lib/epp-client/xml.rb', line 143 def insert_extension(xml1, xml2, pattern = /<clTRID>/) xml1.sub(pattern, "#{xml2}\\&") end |
#raw_builder(opts = {}) {|xml| ... } ⇒ Object
:nodoc:
27 28 29 30 |
# File 'lib/epp-client/xml.rb', line 27 def raw_builder(opts = {}) #:nodoc: xml = Builder::XmlMarkup.new(opts) yield xml end |
#recv_frame_to_xml ⇒ Object
:nodoc:
15 16 17 18 19 |
# File 'lib/epp-client/xml.rb', line 15 def recv_frame_to_xml #:nodoc: @recv_xml = parse_xml(@recv_frame) puts @recv_xml.to_s.gsub(/^/, '<< ') if debug @recv_xml end |
#sent_frame_to_xml ⇒ Object
:nodoc:
21 22 23 24 25 |
# File 'lib/epp-client/xml.rb', line 21 def sent_frame_to_xml #:nodoc: @send_xml = parse_xml(@sent_frame) puts @send_xml.to_s.gsub(/^/, '>> ') if debug @send_xml end |