sroller icon

SOAP call with proxy authorization

sroller | PRO | 03/23/16 01:25:21 AM UTC | 0 ⭐ | 1161 👁️ | Never ⏰ | []
Ruby |

1.41 KB

|

None

|

0 👍

/

0 👎

#!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

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎