Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!ruby
- require 'savon'
- require 'nokogiri'
- require 'pp'
- require 'securerandom'
- # WSDL_URL = 'http://www.webservicex.net/globalweather.asmx?wsdl'
- # we need a local wsdl file because Wasabi cannot deal with proxy authorization
- WSDL_URL = 'weather.wsdl'
- user = "user"
- password = "secret"
- secret = Base64.strict_encode64("#{user}:#{password}")
- client = Savon.client(
- wsdl: WSDL_URL,
- proxy: "http://ubuntu.local:8080",
- headers: { 'Proxy-Authorization' => "Basic #{secret}" },
- log: false, # set true to switch on logging
- log_level: :debug,
- pretty_print_xml: true
- )
- city_name = ARGV[0] || "Waterloo"
- country_name = ARGV[1] || "Canada"
- response = client.call(:get_weather,
- message: { "CityName" => city_name,
- "CountryName" => country_name
- }
- )
- begin
- data = response.to_hash[:get_weather_response][:get_weather_result]
- xml = Nokogiri::XML(data)
- # puts xml.to_xml(:indent => 2)
- loc = xml.at_css('Location').text.strip
- loc.gsub!(/ +,/,',') # clean up for nice display
- time = xml.at_css('Time').text.strip
- temperature = xml.at_css('Temperature').text.strip
- print "location : ", loc, "\n"
- print "time : ", time, "\n"
- print "temperature: ", temperature, "\n"
- rescue Exception => e
- print "sorry: ", e, "\n"
- print "mispelled city or country?\n"
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement