class Github::Authentication::Token
Attributes
expires_at[R]
Public Class Methods
from_json(data)
click to toggle source
# File lib/github/authentication/token.rb, line 10 def self.from_json(data) return nil if data.nil? token, expires_at = JSON.parse(data).values_at('token', 'expires_at') new(token, Time.iso8601(expires_at)) rescue JSON::ParserError nil end
new(token, expires_at)
click to toggle source
# File lib/github/authentication/token.rb, line 19 def initialize(token, expires_at) @token = token @expires_at = expires_at end
Public Instance Methods
expired?(seconds_ttl: 300)
click to toggle source
# File lib/github/authentication/token.rb, line 28 def expired?(seconds_ttl: 300) @expires_at < Time.now.utc + seconds_ttl end
expires_in()
click to toggle source
# File lib/github/authentication/token.rb, line 24 def expires_in (@expires_at - Time.now.utc).to_i end
inspect()
click to toggle source
# File lib/github/authentication/token.rb, line 36 def inspect # Truncating the token should be enough not to leak it in error messages etc "#<#{self.class.name} @token=#{truncate(@token, 10)} @expires_at=#{@expires_at}>" end
to_json()
click to toggle source
# File lib/github/authentication/token.rb, line 41 def to_json JSON.dump(token: @token, expires_at: @expires_at.iso8601) end
to_s()
click to toggle source
# File lib/github/authentication/token.rb, line 45 def to_s @token end
Also aliased as: to_str
valid_for?(ttl)
click to toggle source
# File lib/github/authentication/token.rb, line 32 def valid_for?(ttl) !expired?(seconds_ttl: ttl) end
Private Instance Methods
truncate(string, max)
click to toggle source
# File lib/github/authentication/token.rb, line 52 def truncate(string, max) string.length > max ? "#{string[0...max]}..." : string end