Class: Savon::Service

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

Overview

Savon::Service

Savon::Service is a SOAP client library to enjoy. The goal is to minimize the overhead of working with SOAP services and provide a lightweight alternative to other libraries.

Example

proxy = Savon::Service.new("http://example.com/ExampleService?wsdl")
response = proxy.find_user_by_id(:id => 123)

Constant Summary collapse

SOAPVersions =

Supported SOAP versions.

[1, 2]
ContentType =

Content-Types by SOAP version.

{ 1 => "text/xml", 2 => "application/soap+xml" }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, version = 1) ⇒ Service

Initializer expects an endpoint URI and takes an optional SOAP version.

Raises:

  • (ArgumentError)

34
35
36
37
38
39
40
# File 'lib/savon/service.rb', line 34

def initialize(endpoint, version = 1)
  raise ArgumentError, "Invalid endpoint: #{endpoint}" unless /^http.+/ === endpoint
  raise ArgumentError, "Invalid version: #{version}" unless SOAPVersions.include? version
  @endpoint = URI(endpoint)
  @version = version
  @ssl = /^https.+/ === endpoint
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Catches calls to SOAP actions, checks if the method called was found in the WSDL and dispatches the SOAP action if it's valid. Takes an optional Hash of options to be passed to the SOAP action and an optional XPath- Expression to define a custom XML root node to start parsing the SOAP response at.


137
138
139
140
141
142
143
# File 'lib/savon/service.rb', line 137

def method_missing(method, *args)
  soap_action = camelize(method)
  super unless wsdl.soap_actions.include? soap_action
  soap_body = args[0] || {}
  response_xpath = args[1] || "//return"
  dispatch(soap_action, soap_body, response_xpath)
end

Instance Attribute Details

#pure_response=(value) ⇒ Object (writeonly)

Sets whether the response should be returned as is.


31
32
33
# File 'lib/savon/service.rb', line 31

def pure_response=(value)
  @pure_response = value
end

#wsse_digest=(value) ⇒ Object (writeonly)

Sets whether the WSSE password should be encrypted.


28
29
30
# File 'lib/savon/service.rb', line 28

def wsse_digest=(value)
  @wsse_digest = value
end

#wsse_passwordObject

Accessor for the WSSE password.


25
26
27
# File 'lib/savon/service.rb', line 25

def wsse_password
  @wsse_password
end

#wsse_usernameObject

Accessor for the WSSE username.


22
23
24
# File 'lib/savon/service.rb', line 22

def wsse_username
  @wsse_username
end

Instance Method Details

#pure_response?Boolean

Returns whether the response should be returned as is. Defaults to false.

Returns:

  • (Boolean)

53
54
55
# File 'lib/savon/service.rb', line 53

def pure_response?
  @pure_response == true
end

#wsdlObject

Returns an instance of Savon::WSDL.


43
44
45
# File 'lib/savon/service.rb', line 43

def wsdl
  @wsdl ||= WSDL.new(@endpoint, http)
end

#wsse_digest?Boolean

Returns whether the WSSE password should be encrypted. Defaults to false.

Returns:

  • (Boolean)

48
49
50
# File 'lib/savon/service.rb', line 48

def wsse_digest?
  @wsse_digest == true
end