Sha256: 6c93c821172835ff8638a84b4b1b31543f3d334f6b78b278484ea89ad32ef43b

Contents?: true

Size: 680 Bytes

Versions: 2

Compression:

Stored size: 680 Bytes

Contents

module G5AuthenticationClient::AuthTokenHelper
  # Return response to 'yield'
  # Yield response should have a 'code' method for the http status code
  def do_with_username_pw_access_token
    begin
      response = yield cached_username_pw_access_token
    rescue RestClient::ExceptionWithResponse => e
      response = e.response
    end
    if response.code.to_i == 401
      @cached_username_pw_access_token = nil
      response                         = yield cached_username_pw_access_token
    end
    response
  end

  def cached_username_pw_access_token
    @cached_username_pw_access_token ||= G5AuthenticationClient::Client.new.username_pw_access_token.token
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
g5_authentication_client-0.5.5 lib/g5_authentication_client/auth_token_helper.rb
g5_authentication_client-1.0.0.pre.1 lib/g5_authentication_client/auth_token_helper.rb