class GoogleAdsSavon::SOAP::Request
GoogleAdsSavon::SOAP::Request
¶ ↑
Executes SOAP
requests.
Constants
- CONTENT_TYPE
Content-Types by
SOAP
version.
Attributes
config[RW]
http[RW]
soap[RW]
Public Class Methods
execute(config, http, soap)
click to toggle source
Expects an HTTPI::Request
and a GoogleAdsSavon::SOAP::XML
object to execute a SOAP
request and returns the response.
# File lib/ads_savon/soap/request.rb, line 17 def self.execute(config, http, soap) new(config, http, soap).response end
new(config, http, soap)
click to toggle source
Expects an HTTPI::Request
, a GoogleAdsSavon::SOAP::XML
object and a GoogleAdsSavon::Config
.
# File lib/ads_savon/soap/request.rb, line 23 def initialize(config, http, soap) self.config = config self.soap = soap self.http = configure(http) end
Public Instance Methods
response()
click to toggle source
Executes the request and returns the response.
# File lib/ads_savon/soap/request.rb, line 32 def response @response ||= begin response = config.hooks.fire(:soap_request, self) { with_logging { HTTPI.post(http) } } SOAP::Response.new(config, response) end end
Private Instance Methods
configure(http)
click to toggle source
Configures a given http
from the soap
object.
# File lib/ads_savon/soap/request.rb, line 42 def configure(http) http.url = soap.endpoint if soap.signature? # First generate the document so that Signature can digest sections soap.wsse.signature.document = soap.to_xml(true) # Then re-generate the document so that Signature can sign the digest soap.wsse.signature.document = soap.to_xml(true) # The third time we generate the document, we should have a signature http.body = soap.to_xml(true) else http.body = soap.to_xml end http.headers["Content-Type"] = CONTENT_TYPE[soap.version] http.headers["Content-Length"] = soap.to_xml.bytesize.to_s http end
log_request(url, headers, body)
click to toggle source
Logs the SOAP
request url
, headers
and body
.
# File lib/ads_savon/soap/request.rb, line 72 def log_request(url, headers, body) config.logger.log "SOAP request: #{url}" config.logger.log headers.map { |key, value| "#{key}: #{value}" }.join(", ") config.logger.log body, :pretty => config.pretty_print_xml, :filter => true end
log_response(code, body)
click to toggle source
Logs the SOAP
response code
and body
.
# File lib/ads_savon/soap/request.rb, line 79 def log_response(code, body) config.logger.log "SOAP response (status #{code}):" config.logger.log body, :pretty => config.pretty_print_xml end
with_logging() { || ... }
click to toggle source
Logs the HTTP
request, yields to a given block
and returns a GoogleAdsSavon::SOAP::Response
.
# File lib/ads_savon/soap/request.rb, line 64 def with_logging log_request http.url, http.headers, http.body response = yield log_response response.code, response.body response end