Class: Savon::Client

Inherits:
Object show all
Defined in:
lib/savon/client.rb

Overview

Savon::Client

Savon::Client is the main object for connecting to a SOAP service. It includes methods to access both the Savon::WSDL and Savon::Request object.

Instantiation

Depending on whether you aim to use Savon with or without Savon::WSDL, you need to instantiate Savon::Client by passing in the WSDL or SOAP endpoint.

Client instance with a WSDL endpoint:

client = Savon::Client.new "http://example.com/UserService?wsdl"

Client instance with a SOAP endpoint (for using Savon without a WSDL):

client = Savon::Client.new "http://example.com/UserService"

It is recommended to not use Savon::WSDL for production. Please take a look at the Documentation for Savon::WSDL for more information about how to disable it.

Using a proxy server

You can specify the URI to a proxy server via optional hash arguments.

client = Savon::Client.new "http://example.com/UserService?wsdl", :proxy => "http://proxy.example.com"

Forcing a particular SOAP endpoint

In case you don’t want to use the SOAP endpoint specified in the WSDL, you can tell Savon to use another SOAP endpoint.

client = Savon::Client.new "http://example.com/UserService?wsdl", :soap_endpoint => "http://localhost/UserService"

Gzipped SOAP requests

Sending gzipped SOAP requests can be specified per client instance.

client = Savon::Client.new "http://example.com/UserService?wsdl", :gzip => true

Savon::WSDL

You can access Savon::WSDL via:

client.wsdl

Savon::Request

You can also access Savon::Request via:

client.request

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, options = {}) ⇒ Client

Expects a SOAP endpoint string. Also accepts a Hash of options.

Options:

proxy

the proxy server to use

gzip

whether to gzip SOAP requests

soap_endpoint

force to use this SOAP endpoint



63
64
65
66
67
# File 'lib/savon/client.rb', line 63

def initialize(endpoint, options = {})
  soap_endpoint = options.delete(:soap_endpoint)
  @request = Request.new endpoint, options
  @wsdl = WSDL.new @request, soap_endpoint
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)

Dispatches requests to SOAP actions matching a given method name.



90
91
92
93
94
95
96
# File 'lib/savon/client.rb', line 90

def method_missing(method, *args, &block) #:doc:
  soap_action = soap_action_from method.to_s
  super unless @wsdl.respond_to? soap_action

  setup_objects *@wsdl.operation_from(soap_action), &block
  Response.new @request.soap(@soap)
end

Instance Attribute Details

#requestObject (readonly)

Returns the Savon::Request.



73
74
75
# File 'lib/savon/client.rb', line 73

def request
  @request
end

#wsdlObject (readonly)

Returns the Savon::WSDL.



70
71
72
# File 'lib/savon/client.rb', line 70

def wsdl
  @wsdl
end

Instance Method Details

#call(method, *args, &block) ⇒ Object

Same as method_missing. Workaround for SOAP actions that method_missing does not catch because the method does exist.



83
84
85
# File 'lib/savon/client.rb', line 83

def call(method, *args, &block)
  method_missing method, *args, &block
end

#respond_to?(method) ⇒ Boolean

Returns true for available methods and SOAP actions.

Returns:

  • (Boolean)


76
77
78
79
# File 'lib/savon/client.rb', line 76

def respond_to?(method)
  return true if @wsdl.respond_to? method
  super
end