Class: Savon::Request
Overview
Savon::Request
Handles both WSDL and SOAP HTTP requests.
Constant Summary collapse
- ContentType =
Content-Types by SOAP version.
{ 1 => "text/xml", 2 => "application/soap+xml" }
- @@log =
Whether to log HTTP requests.
true
- @@logger =
The default logger.
Logger.new STDOUT
- @@log_level =
The default log level.
:debug
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the endpoint URI.
-
#open_timeout ⇒ Object
Accessor for HTTP open timeout.
-
#proxy ⇒ Object
readonly
Returns the proxy URI.
-
#read_timeout ⇒ Object
Accessor for HTTP read timeout.
Class Method Summary collapse
-
.log=(log) ⇒ Object
Sets whether to log HTTP requests.
-
.log? ⇒ Boolean
Returns whether to log HTTP requests.
-
.log_level ⇒ Object
Returns the log level.
-
.log_level=(log_level) ⇒ Object
Sets the log level.
-
.logger ⇒ Object
Returns the logger.
-
.logger=(logger) ⇒ Object
Sets the logger.
Instance Method Summary collapse
-
#initialize(endpoint, options = {}) ⇒ Request
constructor
Expects a SOAP
endpoint
String. -
#soap(soap) ⇒ Object
Executes a SOAP request using a given Savon::SOAP instance and returns the Net::HTTPResponse.
-
#wsdl ⇒ Object
Retrieves WSDL document and returns the Net::HTTPResponse.
Constructor Details
#initialize(endpoint, options = {}) ⇒ Request
Expects a SOAP endpoint
String. Also accepts an optional Hash of options
for specifying a proxy server and SSL client authentication.
52 53 54 55 56 |
# File 'lib/savon/request.rb', line 52 def initialize(endpoint, = {}) @endpoint = URI endpoint @proxy = [:proxy] ? URI([:proxy]) : URI("") @ssl = [:ssl] if [:ssl] end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the endpoint URI.
59 60 61 |
# File 'lib/savon/request.rb', line 59 def endpoint @endpoint end |
#open_timeout ⇒ Object
Accessor for HTTP open timeout.
65 66 67 |
# File 'lib/savon/request.rb', line 65 def open_timeout @open_timeout end |
#proxy ⇒ Object (readonly)
Returns the proxy URI.
62 63 64 |
# File 'lib/savon/request.rb', line 62 def proxy @proxy end |
#read_timeout ⇒ Object
Accessor for HTTP read timeout.
68 69 70 |
# File 'lib/savon/request.rb', line 68 def read_timeout @read_timeout end |
Class Method Details
.log=(log) ⇒ Object
Sets whether to log HTTP requests.
21 22 23 |
# File 'lib/savon/request.rb', line 21 def self.log=(log) @@log = log end |
.log? ⇒ Boolean
Returns whether to log HTTP requests.
26 27 28 |
# File 'lib/savon/request.rb', line 26 def self.log? @@log end |
.log_level ⇒ Object
Returns the log level.
46 47 48 |
# File 'lib/savon/request.rb', line 46 def self.log_level @@log_level end |
.log_level=(log_level) ⇒ Object
Sets the log level.
41 42 43 |
# File 'lib/savon/request.rb', line 41 def self.log_level=(log_level) @@log_level = log_level end |
.logger ⇒ Object
Returns the logger.
36 37 38 |
# File 'lib/savon/request.rb', line 36 def self.logger @@logger end |
.logger=(logger) ⇒ Object
Sets the logger.
31 32 33 |
# File 'lib/savon/request.rb', line 31 def self.logger=(logger) @@logger = logger end |
Instance Method Details
#soap(soap) ⇒ Object
Executes a SOAP request using a given Savon::SOAP instance and returns the Net::HTTPResponse.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/savon/request.rb', line 84 def soap(soap) @soap = soap log_request req = Net::HTTP::Post.new @soap.endpoint.path, http_header req.body = @soap.to_xml req.basic_auth(@soap.endpoint.user, @soap.endpoint.password) if @soap.endpoint.user @response = http(@soap.endpoint).start {|h| h.request(req) } log_response @response end |
#wsdl ⇒ Object
Retrieves WSDL document and returns the Net::HTTPResponse.
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/savon/request.rb', line 71 def wsdl log "Retrieving WSDL from: #{@endpoint}" query = @endpoint.path query += ('?' + @endpoint.query) if @endpoint.query req = Net::HTTP::Get.new query req.basic_auth(@endpoint.user, @endpoint.password) if @endpoint.user http.start {|h| h.request(req) } end |