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
37
38
# File 'lib/savon/client.rb', line 32

def initialize(wsdl_document = nil, &block)
  self.config = Savon.config.clone
  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.



168
169
170
171
# File 'lib/savon/client.rb', line 168

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

Instance Attribute Details

#configObject

Accessor for the Savon::Config.



41
42
43
# File 'lib/savon/client.rb', line 41

def config
  @config
end

#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.



61
62
63
# File 'lib/savon/client.rb', line 61

def soap
  @soap
end

Instance Method Details

#httpObject

Returns the HTTPI::Request.



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

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)


76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/savon/client.rb', line 76

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

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

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

#wsdlObject

Returns the Savon::Wasabi::Document.



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

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

#wsseObject

Returns the Akami::WSSE object.



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

def wsse
  @wsse ||= Akami.wsse
end