Class: Blockmason::Link::ManagedSession

Inherits:
Object
  • Object
show all
Defined in:
lib/blockmason/link/managed_session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session:) ⇒ ManagedSession

Returns a new instance of ManagedSession.



8
9
10
# File 'lib/blockmason/link/managed_session.rb', line 8

def initialize(session:)
  @session = session
end

Instance Attribute Details

#sessionObject

Returns the value of attribute session.



6
7
8
# File 'lib/blockmason/link/managed_session.rb', line 6

def session
  @session
end

Instance Method Details

#get(path, inputs) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/blockmason/link/managed_session.rb', line 25

def get(path, inputs)
  begin
    @session.get(path, inputs)
  rescue error
    if error["errors"].any? { |it| it['detail'] =~ /Authentication failed/ }
      @session = @session.refresh!
      @session.get(path, inputs)
    else
      raise error
    end
  end
end

#post(path, inputs) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/blockmason/link/managed_session.rb', line 12

def post(path, inputs)
  begin
    @session.post(path, inputs)
  rescue error
    if error["errors"].any? { |it| it['detail'] =~ /Authentication failed/ }
      @session = @session.refresh!
      @session.post(path, inputs)
    else
      raise error
    end
  end
end