Class: ShellEv::OAuthToken

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/shell_ev/models/o_auth_token.rb

Overview

OAuth 2 Authorization endpoint response

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(access_token = nil, token_type = nil, expires_in = SKIP, scope = SKIP, expiry = SKIP, refresh_token = SKIP) ⇒ OAuthToken

Returns a new instance of OAuthToken.



65
66
67
68
69
70
71
72
73
# File 'lib/shell_ev/models/o_auth_token.rb', line 65

def initialize(access_token = nil, token_type = nil, expires_in = SKIP,
               scope = SKIP, expiry = SKIP, refresh_token = SKIP)
  @access_token = access_token
  @token_type = token_type
  @expires_in = expires_in unless expires_in == SKIP
  @scope = scope unless scope == SKIP
  @expiry = expiry unless expiry == SKIP
  @refresh_token = refresh_token unless refresh_token == SKIP
end

Instance Attribute Details

#access_tokenString

Access token

Returns:

  • (String)


14
15
16
# File 'lib/shell_ev/models/o_auth_token.rb', line 14

def access_token
  @access_token
end

#expires_inInteger

Time in seconds before the access token expires

Returns:

  • (Integer)


22
23
24
# File 'lib/shell_ev/models/o_auth_token.rb', line 22

def expires_in
  @expires_in
end

#expiryInteger

Time of token expiry as unix timestamp (UTC)

Returns:

  • (Integer)


31
32
33
# File 'lib/shell_ev/models/o_auth_token.rb', line 31

def expiry
  @expiry
end

#refresh_tokenString

Refresh token Used to get a new access token when it expires.

Returns:

  • (String)


36
37
38
# File 'lib/shell_ev/models/o_auth_token.rb', line 36

def refresh_token
  @refresh_token
end

#scopeString

List of scopes granted This is a space-delimited list of strings.

Returns:

  • (String)


27
28
29
# File 'lib/shell_ev/models/o_auth_token.rb', line 27

def scope
  @scope
end

#token_typeString

Type of access token

Returns:

  • (String)


18
19
20
# File 'lib/shell_ev/models/o_auth_token.rb', line 18

def token_type
  @token_type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/shell_ev/models/o_auth_token.rb', line 76

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  access_token = hash.key?('access_token') ? hash['access_token'] : nil
  token_type = hash.key?('token_type') ? hash['token_type'] : nil
  expires_in = hash.key?('expires_in') ? hash['expires_in'] : SKIP
  scope = hash.key?('scope') ? hash['scope'] : SKIP
  expiry = hash.key?('expiry') ? hash['expiry'] : SKIP
  refresh_token = hash.key?('refresh_token') ? hash['refresh_token'] : SKIP

  # Create object from extracted values.
  OAuthToken.new(access_token,
                 token_type,
                 expires_in,
                 scope,
                 expiry,
                 refresh_token)
end

.namesObject

A mapping from model property names to API property names.



39
40
41
42
43
44
45
46
47
48
# File 'lib/shell_ev/models/o_auth_token.rb', line 39

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['access_token'] = 'access_token'
  @_hash['token_type'] = 'token_type'
  @_hash['expires_in'] = 'expires_in'
  @_hash['scope'] = 'scope'
  @_hash['expiry'] = 'expiry'
  @_hash['refresh_token'] = 'refresh_token'
  @_hash
end

.nullablesObject

An array for nullable fields



61
62
63
# File 'lib/shell_ev/models/o_auth_token.rb', line 61

def self.nullables
  []
end

.optionalsObject

An array for optional fields



51
52
53
54
55
56
57
58
# File 'lib/shell_ev/models/o_auth_token.rb', line 51

def self.optionals
  %w[
    expires_in
    scope
    expiry
    refresh_token
  ]
end