class Soap4juddi::XML
Public Instance Methods
content_type()
click to toggle source
# File lib/soap4juddi/xml.rb, line 30 def content_type 'text/xml;charset=UTF-8' end
element_with_key_value(element, key, value, attributes = nil)
click to toggle source
# File lib/soap4juddi/xml.rb, line 3 def element_with_key_value(element, key, value, attributes = nil) element_with_value(element, "#{key}:#{value}", attributes) end
element_with_value(element, value, attributes = nil)
click to toggle source
# File lib/soap4juddi/xml.rb, line 7 def element_with_value(element, value, attributes = nil) validate_element(element) xml = "<urn:#{element}" xml = append_key_value_attributes_to_xml(xml, attributes) if attributes xml += ">#{value}</urn:#{element}>" end
envelope_header_body(text, version = 3)
click to toggle source
# File lib/soap4juddi/xml.rb, line 19 def envelope_header_body(text, version = 3) "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:urn='urn:uddi-org:api_v#{version.to_s}'> <soapenv:Header/> <soapenv:Body>#{text.to_s}</soapenv:Body> </soapenv:Envelope>" end
extract_value(soap, key)
click to toggle source
# File lib/soap4juddi/xml.rb, line 14 def extract_value(soap, key) validate_text(soap, 'text') and validate_text(key, 'key') extract_value_in_quotes_using_key(soap, key) end
soap_envelope(message, urn = nil, attributes = nil)
click to toggle source
# File lib/soap4juddi/xml.rb, line 23 def soap_envelope(message, urn = nil, attributes = nil) validate_text(urn, 'urn') if urn validate_text(attributes, 'attributes') if attributes text = inject_urn_and_attributes_into_message(message, urn, attributes) envelope_header_body(text, 2) end
Private Instance Methods
append_key_value_attributes_to_xml(xml, attributes)
click to toggle source
# File lib/soap4juddi/xml.rb, line 42 def append_key_value_attributes_to_xml(xml, attributes) attributes.each do |a, v| xml += " #{a}='#{v}'" end xml end
collapse_spaces_around_equal_sign(soap)
click to toggle source
# File lib/soap4juddi/xml.rb, line 67 def collapse_spaces_around_equal_sign(soap) data = soap data[/\s*=\s*/] = '=' data end
extract_value_in_arbitrary_quotes_following_key_and_equal_sign(soap, key)
click to toggle source
# File lib/soap4juddi/xml.rb, line 73 def extract_value_in_arbitrary_quotes_following_key_and_equal_sign(soap, key) result = soap[/#{key}="(.*?)"/, 1] result ||= soap[/#{key}='(.*?)'/, 1] result end
extract_value_in_quotes_using_key(soap, key)
click to toggle source
# File lib/soap4juddi/xml.rb, line 59 def extract_value_in_quotes_using_key(soap, key) extract_value_in_arbitrary_quotes_following_key_and_equal_sign( collapse_spaces_around_equal_sign(soap), key ) rescue nil end
inject_urn_and_attributes_into_message(message, urn, attributes)
click to toggle source
# File lib/soap4juddi/xml.rb, line 79 def inject_urn_and_attributes_into_message(message, urn, attributes) text = "" text += "<urn:#{urn} generic='2.0' xmlns='urn:uddi-org:api_v2' " + (attributes.nil? ? "" : attributes) + ">" if urn text += message.to_s text += "</urn:#{urn}>" if urn text end
invalid_text?(text)
click to toggle source
# File lib/soap4juddi/xml.rb, line 55 def invalid_text?(text) ((not text.is_a?(String)) or (text.strip == '')) end
validate_element(element)
click to toggle source
# File lib/soap4juddi/xml.rb, line 36 def validate_element(element) raise Soap4juddi::InvalidElementError.new('invalid element provided') if element.nil? raise Soap4juddi::InvalidElementError.new('invalid element provided') if not element.is_a?(String) raise Soap4juddi::InvalidElementError.new('no element provided') if element.strip == '' end
validate_text(text, label)
click to toggle source
# File lib/soap4juddi/xml.rb, line 49 def validate_text(text, label) raise Soap4juddi::InvalidTextError.new("no #{label} provided") if text.nil? raise Soap4juddi::InvalidTextError.new("invalid #{label} provided") if invalid_text?(text) true end