Class: GoogleAdsSavon::Client
- Inherits:
-
Object
- Object
- GoogleAdsSavon::Client
- Defined in:
- lib/ads_savon/client.rb
Overview
GoogleAdsSavon::Client
GoogleAdsSavon::Client is the main object for connecting to a SOAP service.
Instance Attribute Summary collapse
-
#config ⇒ Object
Accessor for the
GoogleAdsSavon::Config
.
Instance Method Summary collapse
-
#http ⇒ Object
Returns the
HTTPI::Request
. -
#initialize(wsdl_document = nil, &block) ⇒ Client
constructor
Initializes the GoogleAdsSavon::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 GoogleAdsSavon::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 = GoogleAdsSavon::Client.new("http://example.com/UserService?wsdl")
# Using a local WSDL
client = GoogleAdsSavon::Client.new File.("../wsdl/service.xml", __FILE__)
# Directly accessing a SOAP endpoint
client = GoogleAdsSavon::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/ads_savon/client.rb', line 33 def initialize(wsdl_document = nil, &block) self.config = GoogleAdsSavon.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 GoogleAdsSavon::Config
.
42 43 44 |
# File 'lib/ads_savon/client.rb', line 42 def config @config end |
Instance Method Details
#http ⇒ Object
Returns the HTTPI::Request
.
50 51 52 |
# File 'lib/ads_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 "<userId>123</userId>"
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: <getUser xmlns:wsdl="http://example.com">...</getUser>"
client.request(:get_user, "xmlns:wsdl" => "http://example.com")
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ads_savon/client.rb', line 73 def request(*args, &block) raise ArgumentError, "GoogleAdsSavon::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/ads_savon/client.rb', line 45 def wsdl @wsdl ||= Wasabi::Document.new end |
#wsse ⇒ Object
Returns the Akami::WSSE
object.
55 56 57 |
# File 'lib/ads_savon/client.rb', line 55 def wsse @wsse ||= Akami.wsse end |