· 1 min read

Screencast: SOAP Webservices mit Savon

Downloads in verschiedenen Formaten:

mp4 m4v webm ogg

Resourcen:

Gemfile

[ruby] gem ‘savon’ [/ruby]

rails console

[ruby] client = Savon::Client.new(“http://www.webservicex.net/uszip.asmx?WSDL”) client.wsdl.soap_actions client.request :web, :get_info_by_zip, body: { “USZip” => “90210” } [/ruby]

models/zip_code.rb

[ruby] class ZipCode attr_reader :state, :city, :area_code, :time_zone def initialize(zip) # Gyoku.convert_symbols_to :camelcase client = Savon::Client.new(“http://www.webservicex.net/uszip.asmx?WSDL”) response = client.request :web, :get_info_by_zip, body: { “USZip” => zip } if response.success? data = response.to_array(:get_info_by_zip_response, :get_info_by_zip_result, :new_data_set, :table).first if data @state = data[:state] @city = data[:city] @area_code = data[:area_code] @time_zone = data[:time_zone] end end end end [/ruby]

Back to Blog