Class: Savon::Request

Inherits:
Object show all
Defined in:
lib/savon/request.rb

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

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
  @endpoint = URI endpoint
  @proxy = options[:proxy] ? URI(options[:proxy]) : URI("") 
  @ssl = options[:ssl] if options[:ssl]
end

Instance Attribute Details

#endpointObject (readonly)

Returns the endpoint URI.



59
60
61
# File 'lib/savon/request.rb', line 59

def endpoint
  @endpoint
end

#proxyObject (readonly)

Returns the proxy URI.



62
63
64
# File 'lib/savon/request.rb', line 62

def proxy
  @proxy
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.

Returns:

  • (Boolean)


26
27
28
# File 'lib/savon/request.rb', line 26

def self.log?
  @@log
end

.log_levelObject

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

.loggerObject

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

#open_timeout=(sec) ⇒ Object

Sets the open timeout for HTTP requests.



65
66
67
# File 'lib/savon/request.rb', line 65

def open_timeout=(sec)
  http.open_timeout = sec
end

#read_timeout=(sec) ⇒ Object

Sets the read timeout for HTTP requests.



70
71
72
# File 'lib/savon/request.rb', line 70

def read_timeout=(sec)
  http.read_timeout = sec
end

#soap(soap) ⇒ Object

Executes a SOAP request using a given Savon::SOAP instance and returns the Net::HTTPResponse.



82
83
84
85
86
87
88
89
# File 'lib/savon/request.rb', line 82

def soap(soap)
  @soap = soap

  log_request
  @response = http.request_post @endpoint.path, @soap.to_xml, http_header
  log_response
  @response
end

#wsdlObject

Retrieves WSDL document and returns the Net::HTTPResponse.



75
76
77
78
# File 'lib/savon/request.rb', line 75

def wsdl
  log "Retrieving WSDL from: #{@endpoint}"
  http.get @endpoint.to_s
end