Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # using a now defunct service
- gem "savon", "~>2.0"
- require "savon"
- require "nokogiri"
- require 'pp'
- soap = Savon.client(
- wsdl: "http://www.webservicex.net/globalweather.asmx?wsdl",
- convert_request_keys_to: :camelcase,
- log: false,
- log_level: :debug,
- pretty_print_xml: true
- )
- country = (ARGV[0] || 'Canada').capitalize
- STDERR.print "Listing cities in #{country}\n"
- response = soap.call(:get_cities_by_country,
- :message => { :country_name => country },
- )
- result = response.to_hash[:get_cities_by_country_response][:get_cities_by_country_result]
- doc = Nokogiri::XML(result)
- # print doc.to_xml(indent: 2)
- cities = doc.xpath("//Table")
- cities.sort{|a,b| a.css('City').text <=> b.css('City').text}.each do |city|
- # two variants to access elements
- # print "#{(city>'City').text} (#{(city>'Country').text})\n"
- print "\"#{city.css('City').text}\" (#{city.css('Country').text})\n"
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement