class Fluxx::Token

API Token handler

Constants

EXPIRATION_DELTA
GRANT_TYPE

Public Class Methods

create(params = {}) click to toggle source

Resource creation helper

@param params [Hash] request parameters to pass to the endpoint @return [Object] instance

Calls superclass method
# File lib/fluxx/token.rb, line 15
def self.create(params = {})
  client_id = Thread.current.thread_variable_get(:FLUXX_CLIENT_ID)
  secret = Thread.current.thread_variable_get(:FLUXX_SECRET)

  super(params.merge(
    grant_type: GRANT_TYPE,
    client_id: client_id || ENV['FLUXX_CLIENT_ID'],
    client_secret: secret || ENV['FLUXX_SECRET']
  ))
end
fresh() click to toggle source

Creates or refreshes a token

@return [Fluxx::Token] instance

# File lib/fluxx/token.rb, line 29
def self.fresh
  @token ||= create
  @expires_in ||= 0

  if Time.now.to_i > @expires_in + @token.expires_in - EXPIRATION_DELTA
    @token = create
    @expires_in = Time.now.to_i
  end

  @token
end