lib/soaspec/exchange_handlers/rest_handler.rb in soaspec-0.0.53 vs lib/soaspec/exchange_handlers/rest_handler.rb in soaspec-0.0.54
- old
+ new
@@ -84,10 +84,17 @@
raise 'File at ' + full_path + ' is not a hash ' unless file_hash.is_a? Hash
oauth_hash = file_hash.transform_keys_to_symbols
oauth2 **oauth_hash
end
+ # @param [Hash] headers Hash of REST headers used in RestClient
+ def headers(headers)
+ define_method('rest_client_headers') do
+ headers
+ end
+ end
+
end
# Wraps around Savon client defining default values dependent on the soap request
class RestHandler < ExchangeHandler
extend Soaspec::RestAccessors
@@ -100,12 +107,18 @@
# Set through following method. Base URL in REST requests.
def base_url_value
nil
end
+ # Headers used in RestClient
+ def rest_client_headers
+ {}
+ end
+
# Add values to here when extending this class to have default REST options.
# See rest client resource at https://github.com/rest-client/rest-client for details
+ # It's easier to set headers via 'headers' accessor rather than here
# @return [Hash] Options adding to & overriding defaults
def rest_resource_options
{
}
end
@@ -120,9 +133,11 @@
name = self.class.to_s
end
super
set_remove_key(options, :default_hash)
merged_options = rest_resource_options
+ merged_options[:headers] ||= {}
+ merged_options[:headers].merge! rest_client_headers
merged_options.merge!(options)
@resource = RestClient::Resource.new(base_url_value, merged_options) # @resource[url_extension].get
end
# Used in together with Exchange request that passes such override parameters
\ No newline at end of file