lib/soaspec/exchange.rb in soaspec-0.0.36 vs lib/soaspec/exchange.rb in soaspec-0.0.37

- old
+ new

@@ -2,23 +2,46 @@ # This represents a request / response pair class Exchange attr_reader :api_class + # How many times to retry for a success + attr_accessor :retry_count + # Set retry for success variable to true so that request will be retried + # for retry_count until it's true + def retry_for_success + @retry_for_success = true + self + end + + # @return [Bool] Whether to keep making request until success code reached + def retry_for_success? + @retry_for_success + end + # @param [Symbol, String] name Name shown in RSpec run # @param [Hash] override_parameters Parameters to override for default params def initialize(name, override_parameters = {}) @test_name = name.to_s @api_class = Soaspec::Environment.api_handler @override_parameters = override_parameters + @retry_for_success = false + self.retry_count = 3 end # Make request to handler with parameters defined + # Will retry until success code reached if retry_for_success? is set + # @return [Response] Response from Api handler def make_request Soaspec::SpecLogger.add_to 'Example ' + @test_name - @api_class.make_request(@override_parameters) + retry_count.times do + response = @api_class.make_request(@override_parameters) + return response unless retry_for_success? + return response if @api_class.status_code_for(response) == 200 + response + end end # Name describing this class when used with `RSpec.describe` # This will make the request and store the response # @return [String] Name given when initializing @@ -36,9 +59,20 @@ # Get status code from api class. This is http response for Web Api # @return [Integer] Status code from api class def status_code @api_class.status_code_for(response) + end + + # Dummy request used to make a request without verifying it and ignoring WSDL errors + # @return [Boolean] Always returns true. Unless of course an unexpected exception occurs + def dummy_request + make_request + true + rescue Savon::HTTPError + puts 'Resolver error' + # This seems to occur first time IP address asks for WSDL + true end # Extract value from path api class # @param [Object] path Path to return element for api class E.g - for SOAP this is XPath string. For JSON, this is Hash dig Array # @return [String] Value at path \ No newline at end of file