Advertisement
sroller

SOAP call with proxy authorization

Mar 22nd, 2016
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.41 KB | None | 0 0
  1. #!ruby
  2.  
  3. require 'savon'
  4. require 'nokogiri'
  5. require 'pp'
  6. require 'securerandom'
  7.  
  8. # WSDL_URL = 'http://www.webservicex.net/globalweather.asmx?wsdl'
  9.  
  10. # we need a local wsdl file because Wasabi cannot deal with proxy authorization
  11. WSDL_URL = 'weather.wsdl'
  12.  
  13. user = "user"
  14. password = "secret"
  15. secret = Base64.strict_encode64("#{user}:#{password}")
  16.  
  17. client = Savon.client(
  18.   wsdl: WSDL_URL,
  19.   proxy: "http://ubuntu.local:8080",
  20.   headers: { 'Proxy-Authorization' => "Basic #{secret}" },
  21.   log: false, # set true to switch on logging
  22.   log_level: :debug,
  23.   pretty_print_xml: true
  24. )
  25.  
  26. city_name = ARGV[0] || "Waterloo"
  27. country_name = ARGV[1] || "Canada"
  28.  
  29. response = client.call(:get_weather,
  30.                        message: { "CityName" => city_name,
  31.                                   "CountryName" => country_name
  32.                                 }
  33.                       )
  34.  
  35. begin
  36.   data = response.to_hash[:get_weather_response][:get_weather_result]
  37.   xml = Nokogiri::XML(data)
  38.   # puts xml.to_xml(:indent => 2)
  39.   loc = xml.at_css('Location').text.strip
  40.   loc.gsub!(/ +,/,',') # clean up for nice display
  41.   time = xml.at_css('Time').text.strip
  42.   temperature = xml.at_css('Temperature').text.strip
  43.  
  44.   print "location   : ", loc, "\n"
  45.   print "time       : ", time, "\n"
  46.   print "temperature: ", temperature, "\n"
  47. rescue Exception => e
  48.   print "sorry: ", e, "\n"
  49.   print "mispelled city or country?\n"
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement