Class: Savon::Client
- Inherits:
-
Object
- Object
- Savon::Client
- 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
-
#config ⇒ Object
Accessor for the Savon::Config.
Instance Method Summary collapse
-
#http ⇒ Object
Returns the HTTPI::Request.
-
#initialize(wsdl_document = nil, &block) ⇒ Client
constructor
Initializes the Savon::Client for a SOAP service.
-
#request(*args, &block) ⇒ Object
Executes a SOAP request for a given SOAP action.
-
#wsdl ⇒ Object
Returns the Wasabi::Document.
-
#wsse ⇒ Object
Returns the Akami::WSSE object.
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
33 34 35 36 37 38 39 |
# File 'lib/savon/client.rb', line 33 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 |
Instance Attribute Details
#config ⇒ Object
Accessor for the Savon::Config.
42 43 44 |
# File 'lib/savon/client.rb', line 42 def config @config end |
Instance Method Details
#http ⇒ Object
Returns the HTTPI::Request.
50 51 52 |
# File 'lib/savon/client.rb', line 50 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 the SOAP::RequestBuilder object to let you access its +soap+, +wsdl+, +http+ and +wsse+ methods.
== Examples
# Calls a "getUser" SOAP action with the payload of "
# 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:
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/savon/client.rb', line 73 def request(*args, &block) raise ArgumentError, "Savon::Client#request requires at least one argument" if args.empty? = (args) request_builder = SOAP::RequestBuilder.new(.delete(:input), ) request_builder.wsdl = wsdl request_builder.http = http.dup request_builder.wsse = wsse.dup request_builder.config = config.dup post_configuration = lambda { process(0, request_builder, &block) if block } response = request_builder.request(&post_configuration).response http.(response.http) if wsse.verify_response WSSE::VerifySignature.new(response.http.body).verify! end response end |
#wsdl ⇒ Object
Returns the Wasabi::Document.
45 46 47 |
# File 'lib/savon/client.rb', line 45 def wsdl @wsdl ||= Wasabi::Document.new end |
#wsse ⇒ Object
Returns the Akami::WSSE object.
55 56 57 |
# File 'lib/savon/client.rb', line 55 def wsse @wsse ||= Akami.wsse end |