Class: DirectoriesInterface::DirectoriesInterfaceWrapper

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

Instance Method Summary collapse

Constructor Details

#initializeDirectoriesInterfaceWrapper

Returns a new instance of DirectoriesInterfaceWrapper.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/directories_interface/directories_interface_wrapper.rb', line 5

def initialize
  # SETUP WEB SERVICES
  @login = Savon::Client.new do
    wsdl.document = "https://secure.directories.ch/administration/v4/security.asmx?WSDL"
  end

  @client = Savon::Client.new do
    wsdl.document = "http://service.directories.ch/search/v4/searchaddress.asmx?WSDL"
  end

  @login.http.auth.ssl.verify_mode = :none
end

Instance Method Details

#login(username, password, service_id) ⇒ Object

returns a sessionID



19
20
21
22
23
24
25
26
# File 'lib/directories_interface/directories_interface_wrapper.rb', line 19

def (username, password, service_id)
   = @login.request "Login", :xmlns => "urn:directories/administration/v4/security" do
    http.headers["SOAPAction"] = '"urn:directories/administration/v4/security/Login"'
    soap.body = '<loginParam>' + XmlParser.(:username=> username, :password=>password, :service_id=>service_id) + '</loginParam>'
  end
   = XmlParser.(.to_hash[:login_response][:login_result])
  XmlParser.extract_session_id() if result_available 
end

#result_available(result_xml) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/directories_interface/directories_interface_wrapper.rb', line 48

def result_available(result_xml)
  error_code = XmlParser.extract_error_code(result_xml)
  error_description = XmlParser.extract_error_description(result_xml)
  case error_code
    when "200" then false
    when "0" then true
    else raise "Service has error: #{error_code} - #{error_description}"
  end
end

#search_address(service_id, session_id, person) ⇒ Object

returns a search result as XML. auth = [ServiceID,SessionID], person = [lastname, firstname, city]



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/directories_interface/directories_interface_wrapper.rb', line 29

def search_address(service_id, session_id, person)
  result = @client.request "SearchAddress", :xmlns =>"urn:directories/search/v4/searchaddress" do
    http.headers["SOAPAction"] = '"urn:directories/search/v4/searchaddress/SearchAddress"'
    soap.body = "<addressParam>" + XmlParser.generate_search_xml(service_id, session_id, person) + "</addressParam>"
  end

  numbers = nil

  if result.success?
    result_xml = XmlParser.extract_search_result(result.to_hash[:search_address_response][:search_address_result])
    if result_available result_xml
      if XmlParser.count_matches(result_xml) == "1"
        numbers = XmlParser.extract_services(result_xml)
      end
    end
  end
  numbers
end