Class: CDEKApiClient::Entities::AuthResponse

Inherits:
Object
  • Object
show all
Includes:
Validatable
Defined in:
lib/cdek_api_client/entities/auth_response.rb

Overview

Represents an OAuth authentication response from the CDEK API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validatable

included, #validate!

Constructor Details

#initialize(access_token:, token_type:, expires_in:, scope:, jti:) ⇒ AuthResponse

Initializes a new AuthResponse object.

Parameters:

  • access_token (String) —

    the access token for API authentication.

  • token_type (String) —

    the type of token (usually "Bearer").

  • expires_in (Integer) —

    the number of seconds until the token expires.

  • scope (String) —

    the scope of the token.

  • jti (String) —

    the unique identifier for the token.

Raises:

  • (ArgumentError) —

    if any attribute validation fails.



27
28
29
30
31
32
33
34
# File 'lib/cdek_api_client/entities/auth_response.rb', line 27

def initialize(access_token:, token_type:, expires_in:, scope:, jti:)
  @access_token = access_token
  @token_type = token_type
  @expires_in = expires_in
  @scope = scope
  @jti = jti
  validate!
end

Instance Attribute Details

#access_token ⇒ Object

Returns the value of attribute access_token.



11
12
13
# File 'lib/cdek_api_client/entities/auth_response.rb', line 11

def access_token
  @access_token
end

#expires_in ⇒ Object

Returns the value of attribute expires_in.



11
12
13
# File 'lib/cdek_api_client/entities/auth_response.rb', line 11

def expires_in
  @expires_in
end

#jti ⇒ Object

Returns the value of attribute jti.



11
12
13
# File 'lib/cdek_api_client/entities/auth_response.rb', line 11

def jti
  @jti
end

#scope ⇒ Object

Returns the value of attribute scope.



11
12
13
# File 'lib/cdek_api_client/entities/auth_response.rb', line 11

def scope
  @scope
end

#token_type ⇒ Object

Returns the value of attribute token_type.



11
12
13
# File 'lib/cdek_api_client/entities/auth_response.rb', line 11

def token_type
  @token_type
end

Instance Method Details

#to_json(*_args) ⇒ String

Converts the AuthResponse object to a JSON representation.

Returns:

  • (String) —

    the JSON representation of the AuthResponse.



39
40
41
42
43
44
45
46
47
# File 'lib/cdek_api_client/entities/auth_response.rb', line 39

def to_json(*_args)
  {
    access_token: @access_token,
    token_type: @token_type,
    expires_in: @expires_in,
    scope: @scope,
    jti: @jti
  }.to_json
end