Class: Berbix::Tokens

Inherits:
Object
  • Object
show all
Defined in:
lib/berbix.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(refresh_token, access_token = nil, client_token = nil, expiry = nil, transaction_id = nil, response = nil) ⇒ Tokens

Returns a new instance of Tokens.



62
63
64
65
66
67
68
69
# File 'lib/berbix.rb', line 62

def initialize(refresh_token, access_token=nil, client_token=nil, expiry=nil, transaction_id=nil, response=nil)
  @refresh_token = refresh_token
  @access_token = access_token
  @client_token = client_token
  @expiry = expiry
  @transaction_id = transaction_id
  @response = response
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



60
61
62
# File 'lib/berbix.rb', line 60

def access_token
  @access_token
end

#client_tokenObject (readonly)

Returns the value of attribute client_token.



60
61
62
# File 'lib/berbix.rb', line 60

def client_token
  @client_token
end

#expiryObject (readonly)

Returns the value of attribute expiry.



60
61
62
# File 'lib/berbix.rb', line 60

def expiry
  @expiry
end

#refresh_tokenObject (readonly)

Returns the value of attribute refresh_token.



60
61
62
# File 'lib/berbix.rb', line 60

def refresh_token
  @refresh_token
end

#responseObject (readonly)

Returns the value of attribute response.



60
61
62
# File 'lib/berbix.rb', line 60

def response
  @response
end

#transaction_idObject (readonly)

Returns the value of attribute transaction_id.



60
61
62
# File 'lib/berbix.rb', line 60

def transaction_id
  @transaction_id
end

#user_idObject (readonly)

Returns the value of attribute user_id.



60
61
62
# File 'lib/berbix.rb', line 60

def user_id
  @user_id
end

Class Method Details

.from_refresh(refresh_token) ⇒ Object



82
83
84
# File 'lib/berbix.rb', line 82

def self.from_refresh(refresh_token)
  Tokens.new(refresh_token)
end

Instance Method Details

#needs_refresh?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/berbix.rb', line 78

def needs_refresh?
  @access_token.nil? || @expiry.nil? || @expiry < Time.now
end

#refresh!(access_token, client_token, expiry, transaction_id) ⇒ Object



71
72
73
74
75
76
# File 'lib/berbix.rb', line 71

def refresh!(access_token, client_token, expiry, transaction_id)
  @access_token = access_token
  @client_token = client_token
  @expiry = expiry
  @transaction_id = transaction_id
end