Class: FriendlyShipping::Services::USPSShip::AccessToken

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

Overview

Represents an access token returned by USPS Ship. 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:, 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

  • raw_token (String)

    the raw JWT token



23
24
25
26
27
# File 'lib/friendly_shipping/services/usps_ship/access_token.rb', line 23

def initialize(token_type:, expires_in:, raw_token:)
  @token_type = token_type
  @expires_in = 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/usps_ship/access_token.rb', line 15

def expires_in
  @expires_in
end

#raw_tokenString (readonly)

Returns the raw JWT token.

Returns:

  • (String)

    the raw JWT token



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

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/usps_ship/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



31
32
33
# File 'lib/friendly_shipping/services/usps_ship/access_token.rb', line 31

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