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"

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 an optional hash of options for specifying a :proxy server to use.



45
46
47
48
# File 'lib/savon/client.rb', line 45

def initialize(endpoint, options = {})
  @request = Request.new endpoint, options
  @wsdl = WSDL.new @request
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.



71
72
73
74
75
76
77
# File 'lib/savon/client.rb', line 71

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.



54
55
56
# File 'lib/savon/client.rb', line 54

def request
  @request
end

#wsdlObject (readonly)

Returns the Savon::WSDL.



51
52
53
# File 'lib/savon/client.rb', line 51

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.



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

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)


57
58
59
60
# File 'lib/savon/client.rb', line 57

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