Class: Fluxx::Token
Overview
API Token handler
Constant Summary collapse
- GRANT_TYPE =
'client_credentials'
- EXPIRATION_DELTA =
60
Constants inherited from Resource
Class Method Summary collapse
-
.create(params = {}) ⇒ Object
Resource creation helper.
-
.fresh ⇒ Fluxx::Token
Creates or refreshes a token.
Methods inherited from Resource
Class Method Details
.create(params = {}) ⇒ Object
Resource creation helper
15 16 17 18 19 20 21 22 23 24 |
# 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 ⇒ Fluxx::Token
Creates or refreshes a token
29 30 31 32 33 34 35 36 37 38 39 |
# 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 |