Sha256: c0aa20b70c20898edab4c764671d53ff0fc04ef6584f594a94d02da17794ee4a

Contents?: true

Size: 495 Bytes

Versions: 3

Compression:

Stored size: 495 Bytes

Contents

require 'singleton'

module ProxyAuth
  # Service token
  class Token
    include Singleton

    attr_accessor :token

    def initialize
      register_service
    end

    def register_service
      Thread.new do
        set_token
      end
    end

    def valid?(token)
      @token == token
    end

    private

    def set_token
      connection = Connection.new
      3.times do
        @token ||= connection.service_token
        @token && break || sleep(5)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
proxy_auth-0.0.6 lib/proxy_auth/token.rb
proxy_auth-0.0.5 lib/proxy_auth/token.rb
proxy_auth-0.0.4 lib/proxy_auth/token.rb