Class: InTimeRuby::AccessTokenGenerator
- Inherits:
-
Object
- Object
- InTimeRuby::AccessTokenGenerator
- Defined in:
- lib/in-time-ruby/access_token_generator.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
Instance Method Summary collapse
- #generate_token ⇒ Object
- #get_access_token ⇒ Object
-
#initialize(client_id, client_secret) ⇒ AccessTokenGenerator
constructor
A new instance of AccessTokenGenerator.
- #save_to_thread!(response) ⇒ Object
- #token_expired? ⇒ Boolean
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
#client ⇒ Object (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_id ⇒ Object (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_secret ⇒ Object (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_token ⇒ Object
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_token ⇒ Object
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
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 |