Class: UspsApi::ClientCredentialsTokenRequest

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/usps_api/models/client_credentials_token_request.rb

Overview

The client credentials are used to get an access token. The credentials of the client application that are verified by the authorization server. The value of the grant_type is ‘client_credentials’

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(redirect_uri:, code:, refresh_token:, client_id:, client_secret:, grant_type: SKIP, scope: SKIP) ⇒ ClientCredentialsTokenRequest

Returns a new instance of ClientCredentialsTokenRequest.



84
85
86
87
88
89
90
91
92
93
# File 'lib/usps_api/models/client_credentials_token_request.rb', line 84

def initialize(redirect_uri:, code:, refresh_token:, client_id:,
               client_secret:, grant_type: SKIP, scope: SKIP)
  @grant_type = grant_type unless grant_type == SKIP
  @scope = scope unless scope == SKIP
  @redirect_uri = redirect_uri
  @code = code
  @refresh_token = refresh_token
  @client_id = client_id
  @client_secret = client_secret
end

Instance Attribute Details

#client_idString

The unique identifier issued to the client application making the request. Used for authenticating the client application. You will need to add an app to get a client Id and secret. These are the Consumer Key and Consumer Secret values respectfully in the API developer portal.

Returns:

  • (String)


48
49
50
# File 'lib/usps_api/models/client_credentials_token_request.rb', line 48

def client_id
  @client_id
end

#client_secretString

The shared secret issued to the client application making the request. Used for authenticating the client application. You will need to add an app to get a client Id and secret. These are the Consumer Key and Consumer Secret values respectfully in the API developer portal.

Returns:

  • (String)


56
57
58
# File 'lib/usps_api/models/client_credentials_token_request.rb', line 56

def client_secret
  @client_secret
end

#codeString

The authorization code previously received by the client application.

Returns:

  • (String)


36
37
38
# File 'lib/usps_api/models/client_credentials_token_request.rb', line 36

def code
  @code
end

#grant_typeGrantType

The OAuth standard flow being requested by the client application.

Returns:



16
17
18
# File 'lib/usps_api/models/client_credentials_token_request.rb', line 16

def grant_type
  @grant_type
end

#redirect_uriString

The authorization code redirect Uniform Resource Identifier (URI) for the third-party application to receive the authorization code. This is used to verify the identify of the requester. The request will not be redirected to this URI.

Returns:

  • (String)


32
33
34
# File 'lib/usps_api/models/client_credentials_token_request.rb', line 32

def redirect_uri
  @redirect_uri
end

#refresh_tokenString

The refresh token value to be used to issue a new access token.

Returns:

  • (String)


40
41
42
# File 'lib/usps_api/models/client_credentials_token_request.rb', line 40

def refresh_token
  @refresh_token
end

#scopeString

The OAuth2 scope being requested. A client application may request a subset of scope that has already been configured during registration. The default scope registered for the client application is used as default when the scope is omitted. **Only specify the scope in the request when the client application requires less scope, i.e. less access to APIs, than the default.**

Returns:

  • (String)


25
26
27
# File 'lib/usps_api/models/client_credentials_token_request.rb', line 25

def scope
  @scope
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/usps_api/models/client_credentials_token_request.rb', line 96

def self.from_hash(hash)
  return nil unless hash

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

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

.namesObject

A mapping from model property names to API property names.



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/usps_api/models/client_credentials_token_request.rb', line 59

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

.nullablesObject

An array for nullable fields



80
81
82
# File 'lib/usps_api/models/client_credentials_token_request.rb', line 80

def self.nullables
  []
end

.optionalsObject

An array for optional fields



72
73
74
75
76
77
# File 'lib/usps_api/models/client_credentials_token_request.rb', line 72

def self.optionals
  %w[
    grant_type
    scope
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/usps_api/models/client_credentials_token_request.rb', line 120

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.redirect_uri,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.code,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.refresh_token,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.client_id,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.client_secret,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['redirect_uri'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['code'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['refresh_token'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['client_id'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['client_secret'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



161
162
163
164
165
166
167
# File 'lib/usps_api/models/client_credentials_token_request.rb', line 161

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

#to_sObject

Provides a human-readable string representation of the object.



153
154
155
156
157
158
# File 'lib/usps_api/models/client_credentials_token_request.rb', line 153

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