lib/savon/request.rb in savon-0.5.3 vs lib/savon/request.rb in savon-0.6.0

- old
+ new

@@ -1,8 +1,11 @@ module Savon + + # == Savon::Request + # + # Handles both WSDL and SOAP HTTP requests. class Request - include Validation # Content-Types by SOAP version. ContentType = { 1 => "text/xml", 2 => "application/soap+xml" } # Defines whether to log HTTP requests. @@ -28,13 +31,16 @@ # Accessor for the default log level. attr_accessor :log_level end - # Expects an endpoint String. + # Expects an endpoint String. Raises an exception in case the given + # +endpoint+ does not seem to be valid. def initialize(endpoint) - validate! :endpoint, endpoint + raise ArgumentError, "Invalid endpoint: #{endpoint}" unless + /^(http|https):\/\// === endpoint + @endpoint = URI endpoint end # Returns the endpoint URI. attr_reader :endpoint @@ -43,31 +49,27 @@ def wsdl log "Retrieving WSDL from: #{@endpoint}" http.get @endpoint.to_s end - # Executes a SOAP request using a given Savon::SOAP (+soap+) instance - # and returns the Net::HTTPResponse. + # Executes a SOAP request using a given Savon::SOAP instance and + # returns the Net::HTTPResponse. def soap(soap) @soap = soap - soap_request + + log_request + @response = http.request_post @endpoint.path, @soap.to_xml, http_header + log_response + @response end private # Logs the SOAP request. def log_request log "SOAP request: #{@endpoint}" log http_header.map { |key, value| "#{key}: #{value}" }.join ", " - log @soap.body - end - - # Executes a SOAP request and returns the Net::HTTPResponse. - def soap_request - log_request - @response = http.request_post @endpoint.path, @soap.body, http_header - log_response - @response + log @soap.to_xml end # Logs the SOAP response. def log_response log "SOAP response (status #{@response.code}):"