lib/soaspec/o_auth2.rb in soaspec-0.2.10 vs lib/soaspec/o_auth2.rb in soaspec-0.2.11

- old
+ new

@@ -5,20 +5,24 @@ class OAuth2 # How often to refresh access token @refresh_token = :always # List of access tokens. They are mapped according to the OAuth parameters used @access_tokens = {} + # List of instance URLs. They are mapped according to the OAuth parameters used + @instance_urls = {} 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: # * :always - (Default) Request token from token url every time it is needed # * :once - Request token once for the entire execution of the suite attr_accessor :refresh_token # @attr [Hash] access_tokens List of access tokens. They are mapped according to the OAuth parameters used attr_accessor :access_tokens + # List of URLs to that define the instance of an application + attr_accessor :instance_urls end # @attr [Hash] OAuth parameters attr_accessor :params # @attr [Integer] Count of tries to obtain access token @@ -43,9 +47,17 @@ params[:username] = api_username || ERB.new(params[:username]).result(binding) if params[:username] params[:security_token] = ERB.new(params[:security_token]).result(binding) if params[:security_token] params[:token_url] = ERB.new(params[:token_url]).result(binding) if params[:token_url] params[:password] = ERB.new(params[:password]).result(binding) if params[:password] Soaspec::SpecLogger.info request_message + end + + # Retrieve instance_url according to access token response. + # Some applications have a different instance + # It's assumed this will be constant for a set of oauth parameters + # @return [String] Instance url + def instance_url + Soaspec::OAuth2.instance_urls[params] ||= response['instance_url'] end # @return [String] Existing or new access token, dependent on refresh_token attribute def access_token case Soaspec::OAuth2.refresh_token