lib/soaspec/exchange_handlers/rest_handler.rb in soaspec-0.3.3 vs lib/soaspec/exchange_handlers/rest_handler.rb in soaspec-0.3.6
- old
+ new
@@ -62,30 +62,12 @@
# @option override_parameters [String] :payload String to be passed directly in request body
# @option override_parameters [String] :template_name Path to file to be read via ERB and passed in request body
# @return [RestClient::Response] Response from making request
def make_request(override_parameters)
req_params = request_parameters override_parameters
- # In order for ERB to be calculated at correct time, the first time request is made, the resource should be created
- @resource ||= RestClient::Resource.new(ERB.new(base_url_value).result(binding), @merged_options)
- @resource_used = req_params.suburl ? @resource[req_params.suburl] : @resource
-
- self.exception = nil # Remove any previously stored exception
- begin
- response = case req_params.method
- when :post, :patch, :put
- Soaspec::SpecLogger.info("request body: #{req_params.post_data}")
- @resource_used.send(req_params.method, req_params.post_data, req_params.other_params)
- else # :get, :delete
- @resource_used.send(req_params.method, req_params.other_params )
- end
- rescue RestClient::Exception => e
- self.exception = e
- raise e unless e.respond_to? :response
-
- response = e.response
- end
- Soaspec::SpecLogger.info("response: \n headers: #{response&.headers}\n body: #{response}\n")
+ response = req_params.call @merged_options
+ Soaspec::SpecLogger.info("response:\n headers: #{response&.headers}\n body: #{response}\n")
after_response(response, self)
response
end
# @param [Hash] override_hash Values to override default hash with
@@ -158,10 +140,10 @@
false
end
# @return [Integer] HTTP Status code for response
def status_code_for(response)
- response.code
+ response&.code
end
# Returns the value at the provided xpath
# @param [RestClient::Response] response
# @param [String] xpath Path to find elements from