lib/ultradns/api/authentication.rb
# Try a request and if there is an authentication failure, retry after
# refreshing the tokens.
#
# yields to the block with the class so that HTTParty class methods can be used.
# Example:  with_auth_retry {|c| c.get '/' }
Try a request and if there is an authentication failure, retry after
refreshing the tokens.

yields to the block with the class so that HTTParty class methods can be used.
Example:  with_auth_retry {|c| c.get '/' }
Try a request and if there is an authentication failure retry after refreshing the tokens . yields to the block with the class so that HTTParty class methods can be used . Example : with_auth_retry { |c| c . get ' / ' }
def refresh
    return auth(@auth[:username], @auth[:password], @auth[:base_url]) if no_expiry?
    return unless refresh?
    requested_at = Time.now.to_i
    response = @client.post('/authorization/token') do |request|
      request.params[:grant_type] = 'refresh_token'
      request.params[:refreshToken] = @auth[:refresh_token]
    end
    logger.debug "Auth Refresh Response: #{response.inspect}"
    raise "Token Refresh Error: #{response.body}" unless response.code == 200
    body = response.parsed_response
    @auth.clear 
    @auth[:requested_at] = requested_at
    @auth[:access_token] = body['accessToken']
    @auth[:refresh_token] = body['refreshToken']
    @auth[:expires_in] = body['expiresIn']
  end
def refresh return auth ( @auth [ :username ] , @auth [ :password ] , @auth [ :base_url ] ) if no_expiry? return unless refresh? requested_at = Time . now . to_i response = @client . post ( '/authorization/token' ) do | request | request . params [ :grant_type ] = 'refresh_token' request . params [ :refreshToken ] = @auth [ :refresh_token ] end logger . debug "Auth Refresh Response: #{response.inspect}" raise "Token Refresh Error: #{response.body}" unless response . code == 200 body = response . parsed_response @auth . clear @auth [ :requested_at ] = requested_at @auth [ :access_token ] = body [ 'accessToken' ] @auth [ :refresh_token ] = body [ 'refreshToken' ] @auth [ :expires_in ] = body [ 'expiresIn' ] end
Try a request and if there is an authentication failure, retry after
refreshing the tokens.
Try a request and if there is an authentication failure retry after refreshing the tokens .
# expires not available, then reauth # not expired yet. # reset everything