Class: UspsApi::ClientApplicationTokenResponse

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

Overview

The OAuth token response for third-party client applications to use to access USPS APIs. The access token is returned in the response. You may use [The Unix Epoch Time Converter](www.epochconverter.com/) to convert access token issued at values to human readable formats. Use the public key provided in the response to verify the access token signature.

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(access_token:, expires_in:, issued_at: SKIP, status: SKIP, issuer: SKIP, scope: SKIP, client_id: SKIP, application_name: SKIP, api_products: SKIP, public_key: SKIP) ⇒ ClientApplicationTokenResponse

Returns a new instance of ClientApplicationTokenResponse.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/usps_api/models/client_application_token_response.rb', line 108

def initialize(access_token:, expires_in:, issued_at: SKIP, status: SKIP,
               issuer: SKIP, scope: SKIP, client_id: SKIP,
               application_name: SKIP, api_products: SKIP, public_key: SKIP)
  @access_token = access_token
  @issued_at = issued_at unless issued_at == SKIP
  @expires_in = expires_in
  @token_type = 'Bearer'
  @status = status unless status == SKIP
  @issuer = issuer unless issuer == SKIP
  @scope = scope unless scope == SKIP
  @client_id = client_id unless client_id == SKIP
  @application_name = application_name unless application_name == SKIP
  @api_products = api_products unless api_products == SKIP
  @public_key = public_key unless public_key == SKIP
end

Instance Attribute Details

#access_tokenString

The access token issued to use to acess protected resources.

Returns:

  • (String)


18
19
20
# File 'lib/usps_api/models/client_application_token_response.rb', line 18

def access_token
  @access_token
end

#api_productsString

The list of API products approved for use by the client application.

Returns:

  • (String)


64
65
66
# File 'lib/usps_api/models/client_application_token_response.rb', line 64

def api_products
  @api_products
end

#application_nameString

The name of the client application.

Returns:

  • (String)


60
61
62
# File 'lib/usps_api/models/client_application_token_response.rb', line 60

def application_name
  @application_name
end

#client_idString

The unique identifier for the client application.

Returns:

  • (String)


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

def client_id
  @client_id
end

#expires_inInteger

The expiration time of the issued access token, in seconds.

Returns:

  • (Integer)


30
31
32
# File 'lib/usps_api/models/client_application_token_response.rb', line 30

def expires_in
  @expires_in
end

#issued_atInteger

The date and time the access token was issued, expressed in Unix epoch time in milliseconds. You may use [The Unix Epoch Time Converter](www.epochconverter.com/) to convert access token issued at values to human readable formats.

Returns:

  • (Integer)


26
27
28
# File 'lib/usps_api/models/client_application_token_response.rb', line 26

def issued_at
  @issued_at
end

#issuerString

The authority that issued the token(s).

Returns:

  • (String)


45
46
47
# File 'lib/usps_api/models/client_application_token_response.rb', line 45

def issuer
  @issuer
end

#public_keyString

The base64-encoded public cryptographic key used to validate the signature of the access token. Validation ensures that the access token has not been tampered with and it originated from a known, trusted source.

Returns:

  • (String)


70
71
72
# File 'lib/usps_api/models/client_application_token_response.rb', line 70

def public_key
  @public_key
end

#scopeString

The OAuth scope being requested by the client application, specified as a list of space-delimited, case-sensitive strings. If ommitted from the token request then the default scope configured for the client application is used.

Returns:

  • (String)


52
53
54
# File 'lib/usps_api/models/client_application_token_response.rb', line 52

def scope
  @scope
end

#statusStatus4

The status of the access token.

Returns:



41
42
43
# File 'lib/usps_api/models/client_application_token_response.rb', line 41

def status
  @status
end

#token_typeString (readonly)

The access token type provides the client with the information required to successfully utilize the access token to make a protected resource request (along with type-specific attributes). The client MUST NOT use an access token if it does not understand the token type.

Returns:

  • (String)


37
38
39
# File 'lib/usps_api/models/client_application_token_response.rb', line 37

def token_type
  @token_type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
151
152
# File 'lib/usps_api/models/client_application_token_response.rb', line 125

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  access_token = hash.key?('access_token') ? hash['access_token'] : nil
  expires_in = hash.key?('expires_in') ? hash['expires_in'] : nil
  issued_at = hash.key?('issued_at') ? hash['issued_at'] : SKIP
  status = hash.key?('status') ? hash['status'] : SKIP
  issuer = hash.key?('issuer') ? hash['issuer'] : SKIP
  scope = hash.key?('scope') ? hash['scope'] : SKIP
  client_id = hash.key?('client_id') ? hash['client_id'] : SKIP
  application_name =
    hash.key?('application_name') ? hash['application_name'] : SKIP
  api_products = hash.key?('api_products') ? hash['api_products'] : SKIP
  public_key = hash.key?('public_key') ? hash['public_key'] : SKIP

  # Create object from extracted values.
  ClientApplicationTokenResponse.new(access_token: access_token,
                                     expires_in: expires_in,
                                     issued_at: issued_at,
                                     status: status,
                                     issuer: issuer,
                                     scope: scope,
                                     client_id: client_id,
                                     application_name: application_name,
                                     api_products: api_products,
                                     public_key: public_key)
end

.namesObject

A mapping from model property names to API property names.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/usps_api/models/client_application_token_response.rb', line 73

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['access_token'] = 'access_token'
  @_hash['issued_at'] = 'issued_at'
  @_hash['expires_in'] = 'expires_in'
  @_hash['token_type'] = 'token_type'
  @_hash['status'] = 'status'
  @_hash['issuer'] = 'issuer'
  @_hash['scope'] = 'scope'
  @_hash['client_id'] = 'client_id'
  @_hash['application_name'] = 'application_name'
  @_hash['api_products'] = 'api_products'
  @_hash['public_key'] = 'public_key'
  @_hash
end

.nullablesObject

An array for nullable fields



104
105
106
# File 'lib/usps_api/models/client_application_token_response.rb', line 104

def self.nullables
  []
end

.optionalsObject

An array for optional fields



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/usps_api/models/client_application_token_response.rb', line 90

def self.optionals
  %w[
    issued_at
    status
    issuer
    scope
    client_id
    application_name
    api_products
    public_key
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/usps_api/models/client_application_token_response.rb', line 156

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.access_token,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.expires_in,
                              ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.token_type,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['access_token'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['expires_in'],
                            ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['token_type'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



190
191
192
193
194
195
196
197
# File 'lib/usps_api/models/client_application_token_response.rb', line 190

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} access_token: #{@access_token.inspect}, issued_at: #{@issued_at.inspect},"\
  " expires_in: #{@expires_in.inspect}, token_type: #{@token_type.inspect}, status:"\
  " #{@status.inspect}, issuer: #{@issuer.inspect}, scope: #{@scope.inspect}, client_id:"\
  " #{@client_id.inspect}, application_name: #{@application_name.inspect}, api_products:"\
  " #{@api_products.inspect}, public_key: #{@public_key.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



181
182
183
184
185
186
187
# File 'lib/usps_api/models/client_application_token_response.rb', line 181

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} access_token: #{@access_token}, issued_at: #{@issued_at}, expires_in:"\
  " #{@expires_in}, token_type: #{@token_type}, status: #{@status}, issuer: #{@issuer}, scope:"\
  " #{@scope}, client_id: #{@client_id}, application_name: #{@application_name}, api_products:"\
  " #{@api_products}, public_key: #{@public_key}>"
end