Class: WalmartApIs::TokenRequest

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/walmart_ap_is/models/token_request.rb

Overview

Form-encoded token request. Fields required depend on grant_type: client_credentials (client auth only), authorization_code (code + code_verifier), refresh_token (refresh_token).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(grant_type:, client_id: SKIP, client_secret: SKIP, code: SKIP, code_verifier: SKIP, refresh_token: SKIP, redirect_uri: SKIP, scope: SKIP, additional_properties: nil) ⇒ TokenRequest

Returns a new instance of TokenRequest.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/walmart_ap_is/models/token_request.rb', line 83

def initialize(grant_type:, client_id: SKIP, client_secret: SKIP,
               code: SKIP, code_verifier: SKIP, refresh_token: SKIP,
               redirect_uri: SKIP, scope: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @grant_type = grant_type
  @client_id = client_id unless client_id == SKIP
  @client_secret = client_secret unless client_secret == SKIP
  @code = code unless code == SKIP
  @code_verifier = code_verifier unless code_verifier == SKIP
  @refresh_token = refresh_token unless refresh_token == SKIP
  @redirect_uri = redirect_uri unless redirect_uri == SKIP
  @scope = scope unless scope == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#client_idString

Client identifier (client_secret_post / public clients). Omit if using HTTP Basic.

Returns:

  • (String)


21
22
23
# File 'lib/walmart_ap_is/models/token_request.rb', line 21

def client_id
  @client_id
end

#client_secretString

Client secret (client_secret_post). Omit for public clients or HTTP Basic.

Returns:

  • (String)


25
26
27
# File 'lib/walmart_ap_is/models/token_request.rb', line 25

def client_secret
  @client_secret
end

#codeString

Authorization code from /auth/v4/authorize (authorization_code grant).

Returns:

  • (String)


29
30
31
# File 'lib/walmart_ap_is/models/token_request.rb', line 29

def code
  @code
end

#code_verifierString

PKCE verifier whose S256 hash equals the earlier code_challenge (authorization_code grant).

Returns:

  • (String)


34
35
36
# File 'lib/walmart_ap_is/models/token_request.rb', line 34

def code_verifier
  @code_verifier
end

#grant_typeGrantType

The OAuth grant type.

Returns:



16
17
18
# File 'lib/walmart_ap_is/models/token_request.rb', line 16

def grant_type
  @grant_type
end

#redirect_uriString

Accepted for OAuth 2.0 back-compat on authorization_code; not required in 2.1 (PKCE covers injection).

Returns:

  • (String)


43
44
45
# File 'lib/walmart_ap_is/models/token_request.rb', line 43

def redirect_uri
  @redirect_uri
end

#refresh_tokenString

A previously issued refresh token (refresh_token grant). Rotated on use.

Returns:

  • (String)


38
39
40
# File 'lib/walmart_ap_is/models/token_request.rb', line 38

def refresh_token
  @refresh_token
end

#scopeString

client_credentials: accepted for compatibility but not honored (ADR-012) — no down-scoping; not echoed. refresh_token: optional; MUST NOT exceed the originally granted scope.

Returns:

  • (String)


49
50
51
# File 'lib/walmart_ap_is/models/token_request.rb', line 49

def scope
  @scope
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/walmart_ap_is/models/token_request.rb', line 101

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  grant_type = hash.key?('grant_type') ? hash['grant_type'] : nil
  client_id = hash.key?('client_id') ? hash['client_id'] : SKIP
  client_secret = hash.key?('client_secret') ? hash['client_secret'] : SKIP
  code = hash.key?('code') ? hash['code'] : SKIP
  code_verifier = hash.key?('code_verifier') ? hash['code_verifier'] : SKIP
  refresh_token = hash.key?('refresh_token') ? hash['refresh_token'] : SKIP
  redirect_uri = hash.key?('redirect_uri') ? hash['redirect_uri'] : SKIP
  scope = hash.key?('scope') ? hash['scope'] : SKIP

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  TokenRequest.new(grant_type: grant_type,
                   client_id: client_id,
                   client_secret: client_secret,
                   code: code,
                   code_verifier: code_verifier,
                   refresh_token: refresh_token,
                   redirect_uri: redirect_uri,
                   scope: scope,
                   additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/walmart_ap_is/models/token_request.rb', line 52

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['grant_type'] = 'grant_type'
  @_hash['client_id'] = 'client_id'
  @_hash['client_secret'] = 'client_secret'
  @_hash['code'] = 'code'
  @_hash['code_verifier'] = 'code_verifier'
  @_hash['refresh_token'] = 'refresh_token'
  @_hash['redirect_uri'] = 'redirect_uri'
  @_hash['scope'] = 'scope'
  @_hash
end

.nullablesObject

An array for nullable fields



79
80
81
# File 'lib/walmart_ap_is/models/token_request.rb', line 79

def self.nullables
  []
end

.optionalsObject

An array for optional fields



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/walmart_ap_is/models/token_request.rb', line 66

def self.optionals
  %w[
    client_id
    client_secret
    code
    code_verifier
    refresh_token
    redirect_uri
    scope
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



143
144
145
146
147
148
149
150
# File 'lib/walmart_ap_is/models/token_request.rb', line 143

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} grant_type: #{@grant_type.inspect}, client_id: #{@client_id.inspect},"\
  " client_secret: #{@client_secret.inspect}, code: #{@code.inspect}, code_verifier:"\
  " #{@code_verifier.inspect}, refresh_token: #{@refresh_token.inspect}, redirect_uri:"\
  " #{@redirect_uri.inspect}, scope: #{@scope.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



134
135
136
137
138
139
140
# File 'lib/walmart_ap_is/models/token_request.rb', line 134

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} grant_type: #{@grant_type}, client_id: #{@client_id}, client_secret:"\
  " #{@client_secret}, code: #{@code}, code_verifier: #{@code_verifier}, refresh_token:"\
  " #{@refresh_token}, redirect_uri: #{@redirect_uri}, scope: #{@scope},"\
  " additional_properties: #{@additional_properties}>"
end