lib/soaspec/o_auth2.rb in soaspec-0.2.27 vs lib/soaspec/o_auth2.rb in soaspec-0.2.28

- old
+ new

@@ -9,10 +9,12 @@ @access_tokens = {} # List of instance URLs. They are mapped according to the OAuth parameters used @instance_urls = {} # Whether to see params sent to & received from oauth URL @request_message = true + # How many times to attempt to authenticate before raising exception + @retry_limit = 2 class << self # Default token url used across entire suite attr_accessor :token_url # @attr [Symbol] refresh_token How often to refresh access token # Values are: @@ -25,11 +27,12 @@ attr_accessor :instance_urls # Specify whether to see params sent to and retrieved from oauth. This will put password in log file, only recommended for debugging attr_writer :debug_oauth # @return [Boolean] Whether to include request message describing OAuth (either full or simplified) attr_writer :request_message - + # @return [Integer] How many times to attempt to authenticate before raising exception + attr_accessor :retry_limit # @return [Boolean] Whether to see params sent to & received from oauth URL def debug_oauth? @debug_oauth || false end @@ -97,10 +100,10 @@ response = RestClient.post(params[:token_url], payload, cache_control: 'no_cache', verify_ssl: false) rescue RestClient::Exception => error Soaspec::SpecLogger.info(["oauth_error: #{error.message}", "oauth_response: #{error.response}"]) self.retry_count += 1 sleep 0.1 # Wait if a bit before retying obtaining access token - retry if retry_count < 3 + retry if retry_count < self.class.retry_limit raise error else Soaspec::SpecLogger.info(["response_headers: #{response.headers}", "response_body: #{response.body}"]) if debug_oauth? JSON.parse(response) end