Class: Mobiscroll::Connect::TokenResponse

Inherits:
Struct
  • Object
show all
Defined in:
lib/mobiscroll/connect/models.rb

Overview

OAuth2 token payload returned by the API.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token

Returns:

  • (Object)

    the current value of access_token



6
7
8
# File 'lib/mobiscroll/connect/models.rb', line 6

def access_token
  @access_token
end

#expires_inObject

Returns the value of attribute expires_in

Returns:

  • (Object)

    the current value of expires_in



6
7
8
# File 'lib/mobiscroll/connect/models.rb', line 6

def expires_in
  @expires_in
end

#refresh_tokenObject

Returns the value of attribute refresh_token

Returns:

  • (Object)

    the current value of refresh_token



6
7
8
# File 'lib/mobiscroll/connect/models.rb', line 6

def refresh_token
  @refresh_token
end

#token_typeObject

Returns the value of attribute token_type

Returns:

  • (Object)

    the current value of token_type



6
7
8
# File 'lib/mobiscroll/connect/models.rb', line 6

def token_type
  @token_type
end

Class Method Details

.from_h(hash) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/mobiscroll/connect/models.rb', line 7

def self.from_h(hash)
  return nil if hash.nil?

  new(
    access_token: hash['access_token'] || hash[:access_token],
    token_type: hash['token_type'] || hash[:token_type],
    expires_in: hash['expires_in'] || hash[:expires_in],
    refresh_token: hash['refresh_token'] || hash[:refresh_token]
  )
end

Instance Method Details

#merged_with(incoming) ⇒ Object

Overlay ‘incoming` on top of self, preserving the existing refresh_token if `incoming` omits one.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mobiscroll/connect/models.rb', line 20

def merged_with(incoming)
  return incoming if nil?

  rt = incoming.refresh_token
  rt = refresh_token if rt.nil? || rt.empty?
  TokenResponse.new(
    access_token: incoming.access_token,
    token_type: incoming.token_type || token_type,
    expires_in: incoming.expires_in || expires_in,
    refresh_token: rt
  )
end

#to_hObject



33
34
35
# File 'lib/mobiscroll/connect/models.rb', line 33

def to_h
  super.compact
end