Class: FlatApi::Tokens

Inherits:
Struct
  • Object
show all
Defined in:
lib/flat_api/oauth.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token

Returns:

  • (Object)

    the current value of access_token



24
25
26
# File 'lib/flat_api/oauth.rb', line 24

def access_token
  @access_token
end

#expires_atObject

Returns the value of attribute expires_at

Returns:

  • (Object)

    the current value of expires_at



24
25
26
# File 'lib/flat_api/oauth.rb', line 24

def expires_at
  @expires_at
end

#refresh_tokenObject

Returns the value of attribute refresh_token

Returns:

  • (Object)

    the current value of refresh_token



24
25
26
# File 'lib/flat_api/oauth.rb', line 24

def refresh_token
  @refresh_token
end

Class Method Details

.from_response(payload) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/flat_api/oauth.rb', line 25

def self.from_response(payload)
  expires_in = payload['expires_in']
  new(
    access_token: payload['access_token'],
    refresh_token: payload['refresh_token'],
    expires_at: expires_in ? Time.now.to_i + expires_in.to_i : nil
  )
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/flat_api/oauth.rb', line 34

def expired?
  !expires_at.nil? && Time.now.to_i >= expires_at - EXPIRY_SKEW
end