Class: Azure::TTS::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/azure/tts/token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#obtained_atObject (readonly)

Returns the value of attribute obtained_at.



6
7
8
# File 'lib/azure/tts/token.rb', line 6

def obtained_at
  @obtained_at
end

#tokenObject (readonly)

Returns the value of attribute token.



6
7
8
# File 'lib/azure/tts/token.rb', line 6

def token
  @token
end

Instance Method Details

#needs_refreshing?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/azure/tts/token.rb', line 18

def needs_refreshing?
  (Time.now.to_i - obtained_at.to_i) > 600
end

#refreshObject

Raises:



8
9
10
11
12
13
14
15
16
# File 'lib/azure/tts/token.rb', line 8

def refresh
  return unless needs_refreshing?

  response = Azure::TTS.api.tokens.post
  raise RequestError, response unless response.success?

  @token = response.body
  @obtained_at = Time.now.to_i
end

#to_sObject



22
23
24
# File 'lib/azure/tts/token.rb', line 22

def to_s
  token
end