Class: DirectoriesInterface::XmlParser

Inherits:
Object
  • Object
show all
Defined in:
lib/directories_interface/xml_parser.rb

Class Method Summary collapse

Class Method Details

.count_matches(xml_res) ⇒ Object



47
48
49
# File 'lib/directories_interface/xml_parser.rb', line 47

def self.count_matches(xml_res)
  xml_res.xpath("//@MatchedEntries").to_s
end

.extract_error_code(xml_res) ⇒ Object



39
40
41
# File 'lib/directories_interface/xml_parser.rb', line 39

def self.extract_error_code(xml_res)
  xml_res.xpath("//@ErrorCode").to_s
end

.extract_error_description(xml_res) ⇒ Object



43
44
45
# File 'lib/directories_interface/xml_parser.rb', line 43

def self.extract_error_description(xml_res)
  xml_res.xpath("//@ErrorDescr").to_s
end

.extract_login_response(soap_login_response) ⇒ Object



27
28
29
# File 'lib/directories_interface/xml_parser.rb', line 27

def self.()
  Nokogiri::XML()
end

.extract_search_result(res) ⇒ Object



35
36
37
# File 'lib/directories_interface/xml_parser.rb', line 35

def self.extract_search_result(res)
  Nokogiri::XML(res)
end

.extract_services(xml_res) ⇒ Object

take the (unique)search result and returns an array of communications



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/directories_interface/xml_parser.rb', line 52

def self.extract_services(xml_res)
  services = xml_res.xpath("//Service[@TypeGrpCode='TEL' or @TypeGrpCode='NATEL' or @TypeGrpCode='FAX' or @TypeGrpCode='EMAIL']")
  result = Array.new
  services.each do |node|
    item = Communication.new
    item.type = node.xpath("@TypeGrpCode").to_s
    item.number = node.xpath("@Value").to_s
    result << item
  end
  result
end

.extract_session_id(login_response) ⇒ Object



31
32
33
# File 'lib/directories_interface/xml_parser.rb', line 31

def self.extract_session_id()
  .xpath("//@SessionId").to_s
end

.generate_login_xml(attr) ⇒ Object



5
6
7
8
9
10
# File 'lib/directories_interface/xml_parser.rb', line 5

def self.(attr)
  res=Nokogiri::XML::Builder.new do  |xml|
    xml.LoginParam(:ServiceId => attr[:service_id], :UserName => attr[:username], :Password => attr[:password])
  end
  coder.encode res.to_xml.to_s.gsub(/\n/,"")
end

.generate_search_xml(service_id, session_id, person) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/directories_interface/xml_parser.rb', line 12

def self.generate_search_xml(service_id,session_id,person)
  res = Nokogiri::XML::Builder.new do |xml|
    xml.AddressParam {
      xml.Authentication(:ServiceId => service_id, :SessionId => session_id)
      xml.Paging(:StartAtIndex => "1", :FinishAtIndex => "5")
      xml.LastName(:Value => person[:lastname], :Phonetic => "1", :PrecisionCode => "FIELDGROUP")
      xml.FirstName(:Value => person[:firstname], :Phonetic => "1", :PrecisionCode => "FIELDGROUP")
      xml.StreetHouseNo(:Value=>person[:address], :Phonetic => "1") if person.has_key?(:address)
      xml.Location(:Value => person[:city], :Phonetic => "0")
      xml.TypeCode "ALL"
    }
  end
  coder.encode res.to_xml.to_s.gsub(/\n/,"")
end