Class: Coyodlee::SessionAuthorization

Inherits:
Object
  • Object
show all
Defined in:
lib/coyodlee/session_authorization.rb

Overview

SessionAuthorization stores cobrand and user session tokens. Its purpose is to make it easy to recreate the Authentication header that must be included in authenticated requests to the Yodlee API

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cobrand_session_token: NullSessionToken.new, user_session_token: NullSessionToken.new) ⇒ SessionAuthorization

Returns a new instance of SessionAuthorization.


20
21
22
23
# File 'lib/coyodlee/session_authorization.rb', line 20

def initialize(cobrand_session_token: NullSessionToken.new, user_session_token: NullSessionToken.new)
  @cobrand_session_token = cobrand_session_token
  @user_session_token = user_session_token
end

Instance Attribute Details

#cobrand_session_tokenSessionToken

Returns the cobrand session token.

Returns:


9
10
11
# File 'lib/coyodlee/session_authorization.rb', line 9

def cobrand_session_token
  @cobrand_session_token
end

#user_session_tokenSessionToken

Returns the user session token.

Returns:


11
12
13
# File 'lib/coyodlee/session_authorization.rb', line 11

def user_session_token
  @user_session_token
end

Class Method Details

.create(authorization = NullSessionAuthorization.new) ⇒ Object


14
15
16
17
# File 'lib/coyodlee/session_authorization.rb', line 14

def create(authorization=NullSessionAuthorization.new)
  new(cobrand_session_token: authorization.cobrand_session_token,
      user_session_token: authorization.user_session_token)
end

Instance Method Details

#to_sString

Returns the cobrand (and user) session as a string to be used in the Authentication header

Returns:

  • (String)

    Returns the cobrand (and user) session as a string to be used in the Authentication header


26
27
28
29
30
31
32
33
# File 'lib/coyodlee/session_authorization.rb', line 26

def to_s
  ['cobSession', 'userSession']
    .zip([@cobrand_session_token, @user_session_token])
    .select { |_, token| token.present? }
    .map { |k, token| [k, token.to_s] }
    .map { |arr| arr.join('=') }
    .join(',')
end