Class: Ksef::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/ksef/session.rb

Overview

An open authenticated session against the KSeF API.

Holds the access/refresh tokens minted by ‘/auth/token/redeem` together with the authentication operation’s reference number. Instances are produced by Ksef::Sessions#open (or #with_interactive) and consumed by resource classes through Client#current_session.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reference_number:, access_token:, refresh_token:, access_token_valid_until: nil, refresh_token_valid_until: nil) ⇒ Session

Returns a new instance of Session.



15
16
17
18
19
20
21
22
23
# File 'lib/ksef/session.rb', line 15

def initialize(reference_number:, access_token:, refresh_token:,
               access_token_valid_until: nil, refresh_token_valid_until: nil)
  @reference_number          = reference_number
  @access_token              = access_token
  @refresh_token             = refresh_token
  @access_token_valid_until  = access_token_valid_until
  @refresh_token_valid_until = refresh_token_valid_until
  @terminated                = false
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



11
12
13
# File 'lib/ksef/session.rb', line 11

def access_token
  @access_token
end

#access_token_valid_untilObject (readonly)

Returns the value of attribute access_token_valid_until.



11
12
13
# File 'lib/ksef/session.rb', line 11

def access_token_valid_until
  @access_token_valid_until
end

#reference_numberObject (readonly)

Returns the value of attribute reference_number.



11
12
13
# File 'lib/ksef/session.rb', line 11

def reference_number
  @reference_number
end

#refresh_tokenObject (readonly)

Returns the value of attribute refresh_token.



11
12
13
# File 'lib/ksef/session.rb', line 11

def refresh_token
  @refresh_token
end

#refresh_token_valid_untilObject (readonly)

Returns the value of attribute refresh_token_valid_until.



11
12
13
# File 'lib/ksef/session.rb', line 11

def refresh_token_valid_until
  @refresh_token_valid_until
end

Instance Method Details

#mark_terminated!Object

Marks the session as closed locally. Network teardown is performed by Ksef::Sessions#terminate.



31
32
33
# File 'lib/ksef/session.rb', line 31

def mark_terminated!
  @terminated = true
end

#terminated?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/ksef/session.rb', line 25

def terminated?
  @terminated
end

#to_sObject Also known as: inspect



35
36
37
38
# File 'lib/ksef/session.rb', line 35

def to_s
  "#<Ksef::Session reference_number=#{@reference_number.inspect} " \
    "terminated=#{@terminated}>"
end