How to use WSDL4R
SOAP4R/1.4.7 includes WSDL4R. Bare in mind this is an alpha level code. I wrote it halfway at half and a year ago, and wrote the rest part in half and a day. No comprehensive test, no strict syntax check, unfriendly error message, etc. Try it if you want, and find bugs in it.
Current WSDL4R includes WSDL -> Ruby command. Let's create a client to connect with Google Web API.
1.
Get GoogleSearch?.wsdl from http://www.google.com/apis/
2.
Run wsdl2ruby.rb
./wsdl2ruby.rb --wsdl GoogleSearch.wsdl --type client --force
You will see the file GoogleSearch?.rb, GoogleSearchDriver?.rb, and GoogleSearchServiceClient?.rb to be created.
3.
GoogleSearchServiceClient?.rb is the file you use. Leave rest 2 files there. Check this file.
require 'GoogleSearchDriver.rb'
endpointUrl = GoogleSearchPort::DefaultEndpointUrl
proxyUrl = ENV[ 'http_proxy' ] || ENV[ 'HTTP_PROXY' ]
obj = GoogleSearchPort.new( endpointUrl, proxyUrl )
# Uncomment the below line to see SOAP wiredumps.
# obj.setWireDumpDev( STDERR )
# SYNOPSIS
# doGetCachedPage( key, url )
#
# ARGS
# key {http://www.w3.org/2001/XMLSchema}string
# url {http://www.w3.org/2001/XMLSchema}string
#
# RETURNS
# return {http://www.w3.org/2001/XMLSchema}base64Binary
#
# RAISES
# N/A
#
key = url = nil
puts obj.doGetCachedPage( key, url )
# SYNOPSIS
# doSpellingSuggestion( key, phrase )
#
# ARGS
# key {http://www.w3.org/2001/XMLSchema}string
# phrase {http://www.w3.org/2001/XMLSchema}string
#
# RETURNS
# return {http://www.w3.org/2001/XMLSchema}string
#
# RAISES
# N/A
#
key = phrase = nil
puts obj.doSpellingSuggestion( key, phrase )
# SYNOPSIS
# doGoogleSearch( key, q, start, maxResults, filter, restrict, safeSearch, lr, ie, oe )
#
# ARGS
# key {http://www.w3.org/2001/XMLSchema}string
# q {http://www.w3.org/2001/XMLSchema}string
# start {http://www.w3.org/2001/XMLSchema}int
# maxResults {http://www.w3.org/2001/XMLSchema}int
# filter {http://www.w3.org/2001/XMLSchema}boolean
# restrict {http://www.w3.org/2001/XMLSchema}string
# safeSearch {http://www.w3.org/2001/XMLSchema}boolean
# lr {http://www.w3.org/2001/XMLSchema}string
# ie {http://www.w3.org/2001/XMLSchema}string
# oe {http://www.w3.org/2001/XMLSchema}string
#
# RETURNS
# return {urn:GoogleSearch}GoogleSearchResult
#
# RAISES
# N/A
#
key = q = start = maxResults = filter = restrict = safeSearch = lr = ie = oe = nil
puts obj.doGoogleSearch( key, q, start, maxResults, filter, restrict, safeSearch, lr, ie, oe )
4.
Run this client without change!
% ruby ./GoogleSearchServiceClient.rb
#<SOAP::RPCUtils::Object:0xa1632c0>: Exception from service object: Invalid authorization key: (SOAP::FaultError)
You must get authorization key from http://www.google.com/apis/ :)
Fortunately, you don't have to create your own Google client. Go http://www.caliban.org/ruby/ruby-google.shtml and get Ruby/Google.
wsdl2ruby.rb can create server side stubs and skelton. See usage of wsdl2ruby.rb.