class Incentivale::Token
Attributes
valid_token[RW]
Public Class Methods
new()
click to toggle source
# File lib/incentivale/token.rb, line 5 def initialize @valid_token = generate_new_token end
Public Instance Methods
access_token()
click to toggle source
# File lib/incentivale/token.rb, line 17 def access_token valid_token['access_token'] end
expired?()
click to toggle source
# File lib/incentivale/token.rb, line 26 def expired? (Time.now.utc - expires_at) >= 0 end
expires_at()
click to toggle source
# File lib/incentivale/token.rb, line 13 def expires_at Time.parse(valid_token['.expires']) end
inspect()
click to toggle source
# File lib/incentivale/token.rb, line 9 def inspect "#<#{self.class.name}:#{object_id}>" end
refresh()
click to toggle source
# File lib/incentivale/token.rb, line 21 def refresh self.valid_token = generate_new_token self end
Private Instance Methods
generate_new_token()
click to toggle source
# File lib/incentivale/token.rb, line 42 def generate_new_token connection = Faraday.new(url: token_host) response = connection.post do |request| request.headers['Content-Type'] = 'application/x-www-form-urlencoded' request.body = URI.encode_www_form(token_grants) end Response.new(response) end
token_grants()
click to toggle source
# File lib/incentivale/token.rb, line 36 def token_grants { username: Incentivale.configuration.username, password: Incentivale.configuration.password, grant_type: :password } end
token_host()
click to toggle source
# File lib/incentivale/token.rb, line 32 def token_host Client.host + '/oauth/token' end