Class: FriendlyShipping::Services::TForceFreight::AccessToken

Inherits:
Object
  • Object
show all
Defined in:
lib/friendly_shipping/services/tforce_freight/access_token.rb

Overview

Represents an access token returned by TForce Freight. The access token can be used to make API requests. Once it expires, a new token must be created.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token_type:, expires_in:, ext_expires_in:, raw_token:) ⇒ AccessToken

Returns a new instance of AccessToken.

Parameters:

  • token_type (String)

    the token's type (typically "Bearer")

  • expires_in (Integer)

    the token's expiration

  • ext_expires_in (Integer)

    the token's extended expiration (only applicable during a service outage)

  • raw_token (String)

    the raw JWT token

See Also:



28
29
30
31
32
33
# File 'lib/friendly_shipping/services/tforce_freight/access_token.rb', line 28

def initialize(token_type:, expires_in:, ext_expires_in:, raw_token:)
  @token_type = token_type
  @expires_in = expires_in
  @ext_expires_in = ext_expires_in
  @raw_token = raw_token
end

Instance Attribute Details

#expires_inInteger (readonly)

Returns the token's expiration.

Returns:

  • (Integer)

    the token's expiration



15
16
17
# File 'lib/friendly_shipping/services/tforce_freight/access_token.rb', line 15

def expires_in
  @expires_in
end

#ext_expires_inInteger (readonly)

Returns the token's extended expiration.

Returns:

  • (Integer)

    the token's extended expiration



18
19
20
# File 'lib/friendly_shipping/services/tforce_freight/access_token.rb', line 18

def ext_expires_in
  @ext_expires_in
end

#raw_tokenString (readonly)

Returns the raw JWT token.

Returns:

  • (String)

    the raw JWT token



21
22
23
# File 'lib/friendly_shipping/services/tforce_freight/access_token.rb', line 21

def raw_token
  @raw_token
end

#token_typeString (readonly)

Returns the token's type.

Returns:

  • (String)

    the token's type



12
13
14
# File 'lib/friendly_shipping/services/tforce_freight/access_token.rb', line 12

def token_type
  @token_type
end

Instance Method Details

#decoded_tokenArray<Hash>

Decodes and returns the raw JWT token.

Returns:

  • (Array<Hash>)

    the decoded token



37
38
39
# File 'lib/friendly_shipping/services/tforce_freight/access_token.rb', line 37

def decoded_token
  @_decoded_token = JWT.decode(raw_token, nil, false)
end