Class: Savon::Request
Overview
Savon::Request
Savon::Request handles both WSDL and SOAP requests.
The Net::HTTP object
You can access the Net::HTTP object used for both WSDL and SOAP requests via:
client.request.http
Here’s an example of how to set open and read timeouts on the Net::HTTP object.
client.request.http.open_timeout = 30
client.request.http.read_timeout = 30
Please refer to the Net::HTTP documentation for more information.
HTTP basic authentication
Setting credentials for HTTP basic authentication:
client.request.basic_auth "username", "password"
SSL client authentication
You can use the methods provided by Net::HTTP to set SSL client authentication or use a shortcut:
client.request.http.ssl_client_auth(
:cert => OpenSSL::X509::Certificate.new(File.read("client_cert.pem")),
:key => OpenSSL::PKey::RSA.new(File.read("client_key.pem"), "password if one exists"),
:ca_file => "cacert.pem",
:verify_mode => OpenSSL::SSL::VERIFY_PEER
)
HTTP headers
There’s an accessor for the Hash of HTTP headers sent with any SOAP call:
client.request.headers["custom"] = "header"
Constant Summary collapse
- ContentType =
Content-Types by SOAP version.
{ 1 => "text/xml;charset=UTF-8", 2 => "application/soap+xml;charset=UTF-8" }
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the endpoint URI.
-
#proxy ⇒ Object
readonly
Returns the proxy URI.
Instance Method Summary collapse
-
#basic_auth(username, password) ⇒ Object
Sets the
username
andpassword
for HTTP basic authentication. -
#headers ⇒ Object
Returns the HTTP headers for a SOAP request.
-
#headers=(headers) ⇒ Object
Sets the HTTP headers for a SOAP request.
-
#http ⇒ Object
Returns the Net::HTTP object.
-
#initialize(endpoint, options = {}) ⇒ Request
constructor
Expects a WSDL or SOAP
endpoint
and accepts a customproxy
address. - #ntlm_auth(username, password) ⇒ Object
-
#soap(soap) ⇒ Object
Executes a SOAP request using a given Savon::SOAP instance and returns the Net::HTTP response.
-
#wsdl ⇒ Object
Retrieves WSDL document and returns the Net::HTTP response.
Methods included from Logger
Constructor Details
#initialize(endpoint, options = {}) ⇒ Request
Expects a WSDL or SOAP endpoint
and accepts a custom proxy
address.
50 51 52 53 54 |
# File 'lib/savon/request.rb', line 50 def initialize(endpoint, = {}) @endpoint = URI endpoint @proxy = URI [:proxy] || "" headers["Accept-encoding"] = "gzip,deflate" if [:gzip] end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the endpoint URI.
57 58 59 |
# File 'lib/savon/request.rb', line 57 def endpoint @endpoint end |
#proxy ⇒ Object (readonly)
Returns the proxy URI.
60 61 62 |
# File 'lib/savon/request.rb', line 60 def proxy @proxy end |
Instance Method Details
#basic_auth(username, password) ⇒ Object
Sets the username
and password
for HTTP basic authentication.
73 74 75 |
# File 'lib/savon/request.rb', line 73 def basic_auth(username, password) @basic_auth = [username, password] end |
#headers ⇒ Object
Returns the HTTP headers for a SOAP request.
63 64 65 |
# File 'lib/savon/request.rb', line 63 def headers @headers ||= {} end |
#headers=(headers) ⇒ Object
Sets the HTTP headers for a SOAP request.
68 69 70 |
# File 'lib/savon/request.rb', line 68 def headers=(headers) @headers = headers if headers.kind_of? Hash end |
#http ⇒ Object
Returns the Net::HTTP object.
102 103 104 |
# File 'lib/savon/request.rb', line 102 def http @http ||= Net::HTTP::Proxy(@proxy.host, @proxy.port).new @endpoint.host, @endpoint.port end |
#ntlm_auth(username, password) ⇒ Object
76 77 78 |
# File 'lib/savon/request.rb', line 76 def ntlm_auth(username, password) @ntlm_auth = [username, password, true] end |
#soap(soap) ⇒ Object
Executes a SOAP request using a given Savon::SOAP instance and returns the Net::HTTP response.
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/savon/request.rb', line 88 def soap(soap) @soap = soap http.endpoint @soap.endpoint.host, @soap.endpoint.port http.use_ssl = @soap.endpoint.ssl? log_request @response = http.start do |h| h.request request(:soap) { |request| request.body = @soap.to_xml } end log_response @response end |
#wsdl ⇒ Object
Retrieves WSDL document and returns the Net::HTTP response.
80 81 82 83 84 85 |
# File 'lib/savon/request.rb', line 80 def wsdl log "Retrieving WSDL from: #{@endpoint}" http.endpoint @endpoint.host, @endpoint.port http.use_ssl = @endpoint.ssl? http.start { |h| h.request request(:wsdl) } end |