Class: Savon::Client

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

Overview

= Savon::Client

Savon::Client is the main object for connecting to a SOAP service.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wsdl_document = nil, &block) ⇒ Client

Initializes the Savon::Client for a SOAP service. Accepts a +block+ which is evaluated in the context of this object to let you access the +wsdl+, +http+, and +wsse+ methods.

== Examples

# Using a remote WSDL client = Savon::Client.new("http://example.com/UserService?wsdl")

# Using a local WSDL client = Savon::Client.new File.expand_path("../wsdl/service.xml", FILE)

# Directly accessing a SOAP endpoint client = Savon::Client.new do wsdl.endpoint = "http://example.com/UserService" wsdl.namespace = "http://users.example.com" end



32
33
34
35
36
# File 'lib/savon/client.rb', line 32

def initialize(wsdl_document = nil, &block)
  wsdl.document = wsdl_document if wsdl_document
  process 1, &block if block
  wsdl.request = http
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Handles calls to undefined methods by delegating to the original block binding.



162
163
164
165
# File 'lib/savon/client.rb', line 162

def method_missing(method, *args, &block)
  super unless original_self
  original_self.send method, *args, &block
end

Instance Attribute Details

#soapObject

Returns the Savon::SOAP::XML object. Please notice, that this object is only available in a block given to Savon::Client#request. A new instance of this object is created per SOAP request.



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

def soap
  @soap
end

Instance Method Details

#httpObject

Returns the HTTPI::Request.



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

def http
  @http ||= HTTPI::Request.new
end

#request(*args, &block) ⇒ Object

Executes a SOAP request for a given SOAP action. Accepts a +block+ which is evaluated in the context of this object to let you access the +soap+, +wsdl+, +http+ and +wsse+ methods.

== Examples

# Calls a "getUser" SOAP action with the payload of "123" client.request(:get_user) { soap.body = { :user_id => 123 } }

# Prefixes the SOAP input tag with a given namespace: "wsdl:GetUser.../wsdl:GetUser" client.request(:wsdl, "GetUser") { soap.body = { :user_id => 123 } }

# SOAP input tag with attributes: ..." client.request(:get_user, "xmlns:wsdl" => "http://example.com")

Raises:

  • (ArgumentError)


71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/savon/client.rb', line 71

def request(*args, &block)
  raise ArgumentError, "Savon::Client#request requires at least one argument" if args.empty?

  self.soap = SOAP::XML.new
  preconfigure extract_options(args)
  process &block if block
  soap.wsse = wsse

  response = SOAP::Request.new(http, soap).response
  set_cookie response.http.headers
  response
end

#wsdlObject

Returns the Savon::Wasabi::Document.



39
40
41
# File 'lib/savon/client.rb', line 39

def wsdl
  @wsdl ||= Wasabi::Document.new
end

#wsseObject

Returns the Akami::WSSE object.



49
50
51
# File 'lib/savon/client.rb', line 49

def wsse
  @wsse ||= Akami.wsse
end