Class: IronBank::Authentications::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/iron_bank/authentications/token.rb

Overview

Get a bearer token to enable authenticated calls to Zuora through OAuth.

Defined Under Namespace

Classes: Error, InvalidAccessToken

Constant Summary collapse

TEN_MINUTES =
600
ONE_HOUR =
3600

Instance Method Summary collapse

Constructor Details

#initialize(client_id:, client_secret:, base_url:) ⇒ Token

Returns a new instance of Token.



19
20
21
22
23
24
# File 'lib/iron_bank/authentications/token.rb', line 19

def initialize(client_id:, client_secret:, base_url:)
  @client_id     = client_id
  @client_secret = client_secret
  @base_url      = base_url
  fetch_token
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/iron_bank/authentications/token.rb', line 26

def expired?
  # Ten minutes as a margin of error in order to renew token in time
  expires_at < Time.now + TEN_MINUTES
end

#headerObject



31
32
33
# File 'lib/iron_bank/authentications/token.rb', line 31

def header
  { "Authorization" => "Bearer #{use}" }
end