Class: InTimeRuby::AccessTokenGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/in-time-ruby/access_token_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id, client_secret) ⇒ AccessTokenGenerator

Returns a new instance of AccessTokenGenerator.



7
8
9
10
11
12
# File 'lib/in-time-ruby/access_token_generator.rb', line 7

def initialize(client_id, client_secret)
  @client_id = client_id
  @client_secret = client_secret

  @client = InTimeRuby::Client.new(token_generation_endpoint, client_id, client_secret, with_authorization: false)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/in-time-ruby/access_token_generator.rb', line 5

def client
  @client
end

#client_idObject (readonly)

Returns the value of attribute client_id.



5
6
7
# File 'lib/in-time-ruby/access_token_generator.rb', line 5

def client_id
  @client_id
end

#client_secretObject (readonly)

Returns the value of attribute client_secret.



5
6
7
# File 'lib/in-time-ruby/access_token_generator.rb', line 5

def client_secret
  @client_secret
end

Instance Method Details

#generate_tokenObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/in-time-ruby/access_token_generator.rb', line 14

def generate_token
  payload = {
    client_id: client_id,
    client_secret: client_secret,
    audience: "https://api.intimebatnr.com",
    grant_type: "client_credentials"
  }

  client.action('/oauth/token', payload: payload)
end

#get_access_tokenObject



31
32
33
# File 'lib/in-time-ruby/access_token_generator.rb', line 31

def get_access_token
  Thread.current["access_token_#{client_id}"]
end

#save_to_thread!(response) ⇒ Object



35
36
37
# File 'lib/in-time-ruby/access_token_generator.rb', line 35

def save_to_thread!(response)
  save_to_thread(response)
end

#token_expired?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/in-time-ruby/access_token_generator.rb', line 25

def token_expired?
  return true unless expire_datetime

  Time.now > expire_datetime
end