lib/soaspec/exchange_handlers/rest_handler.rb in soaspec-0.0.50 vs lib/soaspec/exchange_handlers/rest_handler.rb in soaspec-0.0.51
- old
+ new
@@ -5,10 +5,11 @@
require_relative 'handler_accessors'
require_relative '../interpreter'
require 'json'
require 'jsonpath'
require 'nori'
+require 'erb'
module Soaspec
# Accessors specific to REST handler
module RestAccessors
@@ -108,21 +109,23 @@
{
}
end
# Setup object to handle communicating with a particular SOAP WSDL
- # @param [Hash] specific_options Options defining SOAP request. WSDL, authentication
+ # @param [Hash] options Options defining SOAP request. WSDL, authentication
def initialize(name = self.class.to_s, options = {})
raise "Base URL not set! Please set in class with 'base_url' method" unless base_url_value
+ @default_hash = {}
if name.is_a?(Hash) && options == {} # If name is not set
options = name
name = self.class.to_s
end
+ super
+ set_remove_key(options, :default_hash)
merged_options = rest_resource_options
merged_options.merge!(options)
@resource = RestClient::Resource.new(base_url_value, merged_options) # @resource[url_extension].get
- super
end
# Used in together with Exchange request that passes such override parameters
# @param [Hash] override_parameters Params to characterize REST request
# @param_value [params] Extra parameters (E.g. headers)
@@ -135,17 +138,17 @@
@resource_used = test_values[:suburl] ? @resource[test_values[:suburl]] : @resource
begin
response = case test_values[:method]
- when :post, :patch, :put
- unless test_values[:payload]
- test_values[:payload] = JSON.generate(test_values[:body]).to_s if test_values[:body]
- end
- @resource_used.send(test_values[:method].to_s, test_values[:payload], test_values[:params])
- else
- @resource_used.send(test_values[:method].to_s, test_values[:params])
- end
+ when :post, :patch, :put
+ unless test_values[:payload]
+ test_values[:payload] = JSON.generate(@default_hash.merge(test_values[:body])).to_s if test_values[:body]
+ end
+ @resource_used.send(test_values[:method].to_s, test_values[:payload], test_values[:params])
+ else
+ @resource_used.send(test_values[:method].to_s, test_values[:params])
+ end
rescue RestClient::ExceptionWithResponse => e
response = e.response
end
Soaspec::SpecLogger.add_to('response_headers: ' + response.headers.to_s)
Soaspec::SpecLogger.add_to('response_body: ' + response.to_s)
\ No newline at end of file