Class: DirectoriesInterface::DirectoriesInterfaceWrapper
- Inherits:
-
Object
- Object
- DirectoriesInterface::DirectoriesInterfaceWrapper
- Defined in:
- lib/directories_interface/directories_interface_wrapper.rb
Instance Method Summary collapse
-
#initialize ⇒ DirectoriesInterfaceWrapper
constructor
A new instance of DirectoriesInterfaceWrapper.
-
#login(username, password, service_id) ⇒ Object
returns a sessionID.
- #result_available(result_xml) ⇒ Object
-
#search_address(service_id, session_id, person) ⇒ Object
returns a search result as XML.
Constructor Details
#initialize ⇒ DirectoriesInterfaceWrapper
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 login(username, password, service_id) soap_login_response = @login.request "Login", :xmlns => "urn:directories/administration/v4/security" do http.headers["SOAPAction"] = '"urn:directories/administration/v4/security/Login"' soap.body = '<loginParam>' + XmlParser.generate_login_xml(:username=> username, :password=>password, :service_id=>service_id) + '</loginParam>' end login_response = XmlParser.extract_login_response(soap_login_response.to_hash[:login_response][:login_result]) XmlParser.extract_session_id(login_response) if result_available login_response 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 |