Class: MdNotes::OAuthToken

Inherits:
BaseModel show all
Defined in:
lib/md_notes/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

#method_missing, #respond_to_missing?, #to_hash, #to_json

Constructor Details

#initialize(access_token = nil, token_type = nil, expires_in = nil, scope = nil, expiry = nil, refresh_token = nil, additional_properties = {}) ⇒ OAuthToken

Returns a new instance of OAuthToken.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/md_notes/models/o_auth_token.rb', line 47

def initialize(access_token = nil,
               token_type = nil,
               expires_in = nil,
               scope = nil,
               expiry = nil,
               refresh_token = nil,
               additional_properties = {})
  @access_token = access_token
  @token_type = token_type
  @expires_in = expires_in
  @scope = scope
  @expiry = expiry
  @refresh_token = refresh_token

  # Add additional model properties to the instance.

  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class MdNotes::BaseModel

Instance Attribute Details

#access_tokenString

Access token

Returns:

  • (String)


11
12
13
# File 'lib/md_notes/models/o_auth_token.rb', line 11

def access_token
  @access_token
end

#expires_inLong

Time in seconds before the access token expires

Returns:

  • (Long)


19
20
21
# File 'lib/md_notes/models/o_auth_token.rb', line 19

def expires_in
  @expires_in
end

#expiryLong

Time of token expiry as unix timestamp (UTC)

Returns:

  • (Long)


28
29
30
# File 'lib/md_notes/models/o_auth_token.rb', line 28

def expiry
  @expiry
end

#refresh_tokenString

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

Returns:

  • (String)


33
34
35
# File 'lib/md_notes/models/o_auth_token.rb', line 33

def refresh_token
  @refresh_token
end

#scopeString

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

Returns:

  • (String)


24
25
26
# File 'lib/md_notes/models/o_auth_token.rb', line 24

def scope
  @scope
end

#token_typeString

Type of access token

Returns:

  • (String)


15
16
17
# File 'lib/md_notes/models/o_auth_token.rb', line 15

def token_type
  @token_type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/md_notes/models/o_auth_token.rb', line 68

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.

  access_token = hash['access_token']
  token_type = hash['token_type']
  expires_in = hash['expires_in']
  scope = hash['scope']
  expiry = hash['expiry']
  refresh_token = hash['refresh_token']

  # Clean out expected properties from Hash.

  names.each_value { |k| hash.delete(k) }

  # Create object from extracted values.

  OAuthToken.new(access_token,
                 token_type,
                 expires_in,
                 scope,
                 expiry,
                 refresh_token,
                 hash)
end

.namesObject

A mapping from model property names to API property names.



36
37
38
39
40
41
42
43
44
45
# File 'lib/md_notes/models/o_auth_token.rb', line 36

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